diff --git a/lib/nexrad/afos.py b/lib/nexrad/afos.py index 3b2b855..504259d 100644 --- a/lib/nexrad/afos.py +++ b/lib/nexrad/afos.py @@ -3,8 +3,6 @@ import enum import datetime import shapely -from typing import Self - from nexrad.db import DatabaseTable from nexrad.coord import COORD_SYSTEM from nexrad.vtec import VTECEvent @@ -220,21 +218,26 @@ class AFOSMessageParser(): def parse_body(self, line: str): if line == '&&': self.state = AFOSMessageParserState.TAGS - elif self.timestamp is None: - match = RE_DATE.match(line) + return - if match is not None: - tzoffset = TIMEZONES[match['tz'].upper()] + if self.timestamp is not None: + return - self.timestamp = datetime.datetime( - year = int(match['year']), - month = MONTHS[match['month'].upper()], - day = int(match['day']), - hour = int(match['hour']), - minute = int(match['minute']), - second = 0, - tzinfo = datetime.timezone(datetime.timedelta(hours=tzoffset)) - ).astimezone(datetime.UTC) + match = RE_DATE.match(line) + + if match is not None: + tzoffset = TIMEZONES[match['tz'].upper()] + tzinfo = datetime.timezone(datetime.timedelta(hours=tzoffset)) + + self.timestamp = datetime.datetime( + year = int(match['year']), + month = MONTHS[match['month'].upper()], + day = int(match['day']), + hour = int(match['hour']), + minute = int(match['minute']), + second = 0, + tzinfo = tzinfo + ).astimezone(datetime.UTC) def parse_tags(self, line: str): if line == '$$':