From 5355bfbb3ba1d4e6316df06bf360880d57eace4f Mon Sep 17 00:00:00 2001 From: gjr80 Date: Sat, 22 Feb 2020 12:58:50 +1000 Subject: [PATCH] Fix OverflowError when a WU import encounters an abnormally high epoch timestamp (perhaps in milliseconds) --- bin/weeimport/wuimport.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/weeimport/wuimport.py b/bin/weeimport/wuimport.py index 599b44f3..92319bdb 100644 --- a/bin/weeimport/wuimport.py +++ b/bin/weeimport/wuimport.py @@ -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