Trying to avoid error propagation from Google Weather overuse
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user