You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
669 B

import requests
def get_dad_joke():
print("---Náhodný vtip (icanhazdadjoke.com)---")
url = "https://icanhazdadjoke.com/"
headers = {
"Accept": "application/json",
"User-Agent" : "Python example for students"
}
try:
#odelsaní jednoduchého GET požadavku
response = requests.get(url, headers=headers)
#kontrola žda požadavek proběhl úspěšně
response.raise_for_status()
data = response.json()
print(f"{data['joke']}")
#vtip = data["joke"]
#print(f"{vtip}")
except Exception as e:
print(f"chyba:{e}")
if __name__ == "__main__":
get_dad_joke()