fix: object is not subscriptable #744

This commit is contained in:
Florian Bezannier
2024-02-19 08:06:23 +01:00
parent 6cb6bf6578
commit c67286ac4a
+2 -2
View File
@@ -9,7 +9,7 @@ TIMEOUT_IN_S = 10
def get_temp(latitude: str, longitude: str, api_key: str) -> float:
try:
if not (latitude is None or longitude is None or api_key is None):
if latitude and longitude and api_key:
weather_rep = requests.get("https://api.openweathermap.org/data/2.5/onecall",
params={"lat": latitude, "lon": longitude,
"exclude": "minutely,hourly,daily,alerts",
@@ -17,7 +17,7 @@ def get_temp(latitude: str, longitude: str, api_key: str) -> float:
"units": "metric"},
timeout=TIMEOUT_IN_S)
weather_res_json = weather_rep.json()
temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
temp = weather_res_json.get("current", weather_res_json["main"])["temp"]
logger.debug("Temperature :%fc", temp)
return temp
except ConnectionError: