2 changed files with 31 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||
mkdir 27_owmapi |
|||
cd 27_owmapi |
|||
python -m venv .venv |
|||
.venv\scripts\activate |
|||
pip install requests termcolor |
|||
code . |
|||
@ -0,0 +1,25 @@ |
|||
import requests |
|||
import json |
|||
|
|||
#klíč získáte na https://home.openweathermap.org/api_keys |
|||
KLIC = "cdcbb82b14e8e3e85117686c68e19a5b" |
|||
MESTO = input("Zadej město: ") |
|||
|
|||
# & = AltGR + C ; {|} = AltGR + B|N |
|||
url1 = f"https://api.openweathermap.org/data/2.5/" |
|||
url2 = f"weather?q={MESTO}&appid={KLIC}&units=metric" |
|||
url = url1 + url2 |
|||
|
|||
print(f"Otevírám odkaz: {url}") |
|||
odpoved = requests.get(url) |
|||
odpoved.raise_for_status() |
|||
data = odpoved.json() |
|||
#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}") |
|||
Loading…
Reference in new issue