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.
27 lines
719 B
27 lines
719 B
import requests
|
|
from termcolor import colored
|
|
|
|
|
|
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"\n{colored(data['joke'],"green")}")
|
|
#vtip = data["joke"]
|
|
#print(f"{vtip}")
|
|
except Exception as e:
|
|
print(f"chyba:{e}")
|
|
|
|
if __name__ == "__main__":
|
|
get_dad_joke()
|