From bed62435b069e52ae290304885471f3dcb743550 Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Mon, 9 Mar 2026 09:36:10 +0100 Subject: [PATCH] owm api --- 27_owmapi/poznamky.txt | 6 ++++++ 27_owmapi/rychly_pocasi.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 27_owmapi/poznamky.txt create mode 100644 27_owmapi/rychly_pocasi.py diff --git a/27_owmapi/poznamky.txt b/27_owmapi/poznamky.txt new file mode 100644 index 0000000..d142c03 --- /dev/null +++ b/27_owmapi/poznamky.txt @@ -0,0 +1,6 @@ +mkdir 27_owmapi +cd 27_owmapi +python -m venv .venv +.venv\scripts\activate +pip install requests termcolor +code . \ No newline at end of file diff --git a/27_owmapi/rychly_pocasi.py b/27_owmapi/rychly_pocasi.py new file mode 100644 index 0000000..1e2489e --- /dev/null +++ b/27_owmapi/rychly_pocasi.py @@ -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}") \ No newline at end of file