4 changed files with 71 additions and 0 deletions
|
After Width: | Height: | Size: 4.0 MiB |
@ -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}") |
|||
@ -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") |
|||
@ -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() |
|||
Loading…
Reference in new issue