Trying to avoid error propagation from Google Weather overuse

This commit is contained in:
2026-05-25 01:58:52 +00:00
parent da0bbbf918
commit f40662ab27
3 changed files with 22 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ def get_current_weather(api_key, lat, lng, units="IMPERIAL"):
return response.json()
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
#print(f"An error occurred: {e}")
return None
def get_daily_forecast(api_key, lat, lng, days=2):
@@ -51,7 +51,7 @@ def get_daily_forecast(api_key, lat, lng, days=2):
return data
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
#print(f"An error occurred: {e}")
return None
def get_google_weather():
@@ -71,6 +71,8 @@ def get_google_weather():
theweather["current"] = (f"{condition}") + (f", {temp.get('degrees')}°F")\
+ (f", {humidity}%") + (f" hum., Feels like: {feels_like.get('degrees')}°F")
else: # current_data not returned
theweather["current"] = "Problem retrieving current weather"
forecast_data = get_daily_forecast(API_KEY, LATITUDE, LONGITUDE)
@@ -85,6 +87,8 @@ def get_google_weather():
min_temp = day.get("minTemperature", {}).get("degrees")
condition = day.get("daytimeForecast", {}).get("weatherCondition", {}).get("description", {}).get("text")
theweather["forecast_tomorrow"] = (f"{condition}") + (f", {min_temp}°F-{max_temp}°F")
else:
theweather["forecast_tomorrow"] = "Problem retrieving weather forecast"
return theweather