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).
This commit is contained in:
Erik Johnson 2017-01-31 11:11:27 -06:00
parent 86634f8f8a
commit 82555cb6a7

View File

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