From 82555cb6a711b00dbd3624d7967d2bde8e78bac6 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 31 Jan 2017 11:11:27 -0600 Subject: [PATCH] Fall back to local_epoch if observation_epoch is non-numeric This fixes a traceback when the weather data is incomplete (possibly due to a PWS being on the fritz). --- i3pystatus/weather/wunderground.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/i3pystatus/weather/wunderground.py b/i3pystatus/weather/wunderground.py index f2d40b9..7b1f7b2 100644 --- a/i3pystatus/weather/wunderground.py +++ b/i3pystatus/weather/wunderground.py @@ -239,10 +239,13 @@ class Wunderground(WeatherBackend): return str(data.get(key, default)) try: - observation_time = datetime.fromtimestamp( - int(_find('observation_epoch')) + observation_epoch = _find('observation_epoch') or _find('local_epoch') + observation_time = datetime.fromtimestamp(int(observation_epoch)) + except (TypeError, ValueError): + log.debug( + 'Observation time \'%s\' is not a UNIX timestamp', + observation_epoch ) - except TypeError: observation_time = datetime.fromtimestamp(0) self.data['city'] = _find('city', response['observation_location'])