Further simplify code

This commit is contained in:
XANTRONIX Industrial 2025-02-20 13:35:56 -05:00
parent 52978b267f
commit 44bd511347

View file

@ -3,8 +3,6 @@ import enum
import datetime import datetime
import shapely import shapely
from typing import Self
from nexrad.db import DatabaseTable from nexrad.db import DatabaseTable
from nexrad.coord import COORD_SYSTEM from nexrad.coord import COORD_SYSTEM
from nexrad.vtec import VTECEvent from nexrad.vtec import VTECEvent
@ -220,21 +218,26 @@ class AFOSMessageParser():
def parse_body(self, line: str): def parse_body(self, line: str):
if line == '&&': if line == '&&':
self.state = AFOSMessageParserState.TAGS self.state = AFOSMessageParserState.TAGS
elif self.timestamp is None: return
match = RE_DATE.match(line)
if match is not None: if self.timestamp is not None:
tzoffset = TIMEZONES[match['tz'].upper()] return
self.timestamp = datetime.datetime( match = RE_DATE.match(line)
year = int(match['year']),
month = MONTHS[match['month'].upper()], if match is not None:
day = int(match['day']), tzoffset = TIMEZONES[match['tz'].upper()]
hour = int(match['hour']), tzinfo = datetime.timezone(datetime.timedelta(hours=tzoffset))
minute = int(match['minute']),
second = 0, self.timestamp = datetime.datetime(
tzinfo = datetime.timezone(datetime.timedelta(hours=tzoffset)) year = int(match['year']),
).astimezone(datetime.UTC) 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): def parse_tags(self, line: str):
if line == '$$': if line == '$$':