diff --git a/03_get_send_data/image.gif b/03_get_send_data/image.gif new file mode 100644 index 0000000..65066cc Binary files /dev/null and b/03_get_send_data/image.gif differ diff --git a/03_get_send_data/jokes.py b/03_get_send_data/jokes.py new file mode 100644 index 0000000..1f0ccd1 --- /dev/null +++ b/03_get_send_data/jokes.py @@ -0,0 +1,17 @@ +# python -m venv .venv +# .venv\Scripts\activate +# pip install requests matplotlib +# pip list + +import requests +url = "https://api.chucknorris.io/jokes/random" + +while(input("Nex joke? q = quit:") != "q"): + response = requests.get(url) + + if response.status_code == 200: + data = response.json() + print(f"Joke: {data["value"]}") + print(data["created_at"]) + else: + print(f"Chyba: {response.status_code}") \ No newline at end of file diff --git a/03_get_send_data/thingspeak.py b/03_get_send_data/thingspeak.py new file mode 100644 index 0000000..646a01b --- /dev/null +++ b/03_get_send_data/thingspeak.py @@ -0,0 +1,31 @@ +import requests +import random +import time + +WRITE_API_KEY = "VÁŠ_WRITE_API_KEY" +SEND_TIME = 15 + +def odeslat_data(hodnota): + url = f"https://api.thingspeak.com/update?api_key={WRITE_API_KEY}&field1={hodnota}" + try: + response = requests.get(url) + if response.status_code == 200: + if response.text == "0": + print("ThingSpeak odmítl zápis") + else: + print("Úspěšně odesláno") + else: + print(f"Chyba serveru: {response.status_code}") + except Exception as e: + print(f"Chyba:{e}") + +if __name__ == "__main__": + print("Připravuji odesílaní dat, pro ukonční použíjte CTRL+C") + try: + while True: + nahodne_cislo = random.randint(10,30) + odeslat_data(nahodne_cislo) + print(f"Čekám {SEND_TIME} vteřin na další odeslání") + time.sleep(SEND_TIME) + except KeyboardInterrupt: + print("\nProgram ukončen uživatelem") \ No newline at end of file diff --git a/03_get_send_data/yesno.py b/03_get_send_data/yesno.py new file mode 100644 index 0000000..11e6157 --- /dev/null +++ b/03_get_send_data/yesno.py @@ -0,0 +1,23 @@ +import requests +from PIL import Image +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +response = requests.get("https://yesno.wtf/api") +if response.status_code == 200: + data = response.json() + print(data["answer"]) + image_url = data["image"] + image_response = requests.get(image_url) + with open("image.gif","wb") as f: + f.write(image_response.content) + image = Image.open("image.gif") + num_frames = image.n_frames + def update_image(frame_num): + image.seek(frame_num) + plt.imshow(image) + anim = animation.FuncAnimation(plt.gcf(), + update_image,interval=40,frames=num_frames) + plt.title(data["answer"]) + plt.show() + exit() \ No newline at end of file