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).
@@ -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'])
