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.
43 lines
902 B
43 lines
902 B
import requests
|
|
|
|
base_url = "http://localhost:8000/api"
|
|
|
|
options = {
|
|
"1": "Zobrazit vše",
|
|
"2": "Zobrazit teplotu",
|
|
"3": "Zobrazit vlhkost"
|
|
}
|
|
|
|
while True:
|
|
for key, value in options.items():
|
|
print(f"{key}:{value}")
|
|
|
|
vyber = input("Zadejte cislo volby:")
|
|
if vyber in options:
|
|
break
|
|
else:
|
|
print("Spatna volba")
|
|
|
|
if vyber == "1":
|
|
url = f"{base_url}/data"
|
|
elif vyber == "2":
|
|
url = f"{base_url}/teplota"
|
|
elif vyber == "3":
|
|
url = f"{base_url}/vlhkost"
|
|
|
|
response = requests.get(url)
|
|
|
|
if response.status_code == 200: #uspěšné připojení
|
|
data = response.json()
|
|
if vyber == "1":
|
|
print(data)
|
|
if vyber == "2":
|
|
teplota = data["teplota"]
|
|
print(f"Teplota: {teplota}°C")
|
|
if vyber == "3":
|
|
vlhkost = data["vlhkost"]
|
|
print(f"Vlhkost: {vlhkost}%")
|
|
else:
|
|
print("Chyba:", response.status_code)
|
|
|
|
|
|
|