diff --git a/src/main.py b/src/main.py index d775739..4f7af2f 100644 --- a/src/main.py +++ b/src/main.py @@ -93,11 +93,13 @@ def register(): sqlsession.commit() return f"
diff --git a/src/weather_api.py b/src/weather_api.py
index e898a33..9aa012f 100644
--- a/src/weather_api.py
+++ b/src/weather_api.py
@@ -1,3 +1,4 @@
+import os
import requests
import json
@@ -12,15 +13,15 @@ def decode_weather(weather):
return temp, humidity, type, rain
-def get_weather():
- weather_request = requests.get(
- "http://samples.openweathermap.org/data/2.5/weather?q=Warsaw,pl&units=metric"
- )
-
- # Czyszczenie odpowiedzi...
+def get_weather(city):
+ api_key = os.environ.get("OPENWEATHER_API_KEY")
+ if not api_key:
+ raise Exception("Brak klucza API w zmiennej środowiskowej OPENWEATHER_API_KEY")
+ url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&units=metric&appid={api_key}&lang=pl"
+ weather_request = requests.get(url)
+ if weather_request.status_code != 200:
+ return None
weather = weather_request.content.strip()
-
temp, humidity, type, rain = decode_weather(weather)
-
return temp, humidity, type, rain