Fix OverflowError when a WU import encounters an abnormally high epoch timestamp (perhaps in milliseconds)

This commit is contained in:
gjr80
2020-02-22 12:58:50 +10:00
parent d9e4790ee8
commit 5355bfbb3b

View File

@@ -295,9 +295,16 @@ class WUSource(weeimport.Source):
# it's not there so skip it
pass
if obs == 'epoch':
# An epoch timestamp could be in seconds or
# milliseconds, WeeWX uses seconds. We can check by
# trying to convert the epoch value into a datetime
# object, if the epoch value is in milliseconds it will
# fail. In that case divide the epoch value by 1000.
# Note we would normally expect to see a ValueError but
# on armhf platforms we might see an OverflowError.
try:
_date = datetime.date.fromtimestamp(_flat_record['epoch'])
except ValueError:
except (ValueError, OverflowError):
_flat_record['epoch'] = _flat_record['epoch'] // 1000
# WU in its wisdom provides min and max pressure but no average
# pressure (unlike other obs) so we need to calculate it. If