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
712 B
25 lines
712 B
import requests
|
|
import json
|
|
|
|
#klíč získate na https://home.openweathermap.org/api_keys
|
|
KLIC = "f70d944f638a7ae77de89435d4d23c01"
|
|
MESTO = input("Zadej město:")
|
|
# AltGR + C = &
|
|
url1 = f"https://api.openweathermap.org/data/2.5/"
|
|
url2 = f"weather?q={MESTO}&appid={KLIC}&units=metric&lang=cz"
|
|
url = url1 + url2
|
|
|
|
print(f"Otevírám odkaz: {url}")
|
|
odpoved = requests.get(url)
|
|
odpoved.raise_for_status()
|
|
data = odpoved.json()
|
|
#pro výpis celé json odpovědi
|
|
print(json.dumps(data,indent=4,ensure_ascii=False))
|
|
|
|
popis = data["weather"][0]["description"]
|
|
teplota = data["main"]["temp"]
|
|
owm_mesto = data["name"]
|
|
|
|
print(f"Město: {owm_mesto} (napsáno:{MESTO})")
|
|
print(f"Teplota: {teplota}°C")
|
|
print(f"Popis: {popis}")
|