summaryrefslogtreecommitdiff
path: root/cached
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-10-19 16:40:34 -0700
committerScott Gasch <[email protected]>2021-10-19 16:40:34 -0700
commit351e77c767c9084aa486eedbdc9902c635b06261 (patch)
treeb41e328293b8f89ea8f56f02e451ea2afe7c2e2e /cached
parent9484900f080e16f118806fe54973e69d36b043e8 (diff)
Bugfixes.
Diffstat (limited to 'cached')
-rw-r--r--cached/weather_forecast.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/cached/weather_forecast.py b/cached/weather_forecast.py
index 6e2f5f9..a413d9f 100644
--- a/cached/weather_forecast.py
+++ b/cached/weather_forecast.py
@@ -59,15 +59,23 @@ class CachedDetailedWeatherForecast(object):
self.forecasts = {}
# Ask the raspberry pi about the outside temperature.
- www = urllib.request.urlopen(
- "http://10.0.0.75/~pi/outside_temp"
- )
- current_temp = www.read().decode("utf-8")
- current_temp = float(current_temp)
- current_temp *= (9/5)
- current_temp += 32.0
- current_temp = round(current_temp)
- www.close()
+ www = None
+ try:
+ www = urllib.request.urlopen(
+ "http://10.0.0.75/~pi/outside_temp",
+ timeout=2,
+ )
+ current_temp = www.read().decode("utf-8")
+ current_temp = float(current_temp)
+ current_temp *= (9/5)
+ current_temp += 32.0
+ current_temp = round(current_temp)
+ except Exception:
+ logger.warning('Timed out reading 10.0.0.75/~pi/outside_temp?!')
+ current_temp = None
+ finally:
+ if www is not None:
+ www.close()
# Get a weather forecast for Bellevue.
www = urllib.request.urlopen(
@@ -102,7 +110,7 @@ class CachedDetailedWeatherForecast(object):
sunrise = s['sunrise']
sunset = s['sunset']
- if dt.date() == now.date() and not said_temp:
+ if dt.date() == now.date() and not said_temp and current_temp is not None:
blurb = f'{day.get_text()}: The current outside tempterature is {current_temp}. '
blurb += txt.get_text()
said_temp = True