Sort parser out a bit more
This commit is contained in:
parent
c0221f30f0
commit
b884d060b8
1 changed files with 45 additions and 16 deletions
|
@ -93,7 +93,7 @@ class SPCOutlookArea():
|
|||
area_type = None
|
||||
threat = None
|
||||
category = None
|
||||
points = None
|
||||
points = list()
|
||||
|
||||
for line in text.split('\n'):
|
||||
if line is None:
|
||||
|
@ -101,14 +101,14 @@ class SPCOutlookArea():
|
|||
|
||||
line = line.rstrip()
|
||||
|
||||
if line == '':
|
||||
continue
|
||||
|
||||
if state is SPCOutlookParserState.HEADER:
|
||||
if line == '':
|
||||
continue
|
||||
|
||||
match = RE_HEADER.match(line)
|
||||
|
||||
if match is None:
|
||||
raise SPCOutlookParserException(f"Unexpected header value, got {line}")
|
||||
raise SPCOutlookParserException(f"Unexpected header value, got '{line}'")
|
||||
|
||||
area.day = int(match['day'])
|
||||
|
||||
|
@ -148,6 +148,9 @@ class SPCOutlookArea():
|
|||
|
||||
state = SPCOutlookParserState.VALIDITY
|
||||
elif state is SPCOutlookParserState.VALIDITY:
|
||||
if line == '':
|
||||
continue
|
||||
|
||||
match = RE_VALIDITY.match(line)
|
||||
|
||||
if match is None:
|
||||
|
@ -194,36 +197,62 @@ class SPCOutlookArea():
|
|||
|
||||
state = SPCOutlookParserState.AREA_THREAT
|
||||
elif state is SPCOutlookParserState.AREA_THREAT:
|
||||
if line == '&&':
|
||||
if line == '':
|
||||
continue
|
||||
elif line == '&&':
|
||||
print(f"Done getting points, area type {area_type} threat {threat}")
|
||||
|
||||
threat = None
|
||||
category = None
|
||||
points = None
|
||||
points = list()
|
||||
continue
|
||||
|
||||
#
|
||||
# Check for an area type.
|
||||
#
|
||||
match = RE_AREA_TYPE.match(line)
|
||||
|
||||
if match is not None:
|
||||
area_type = match['type']
|
||||
continue
|
||||
|
||||
#
|
||||
# Check for an area threat.
|
||||
#
|
||||
match = RE_THREAT.match(line)
|
||||
|
||||
if match is not None:
|
||||
threat = match['type']
|
||||
continue
|
||||
|
||||
if points is None:
|
||||
match = RE_POINTS_START.match(line)
|
||||
#
|
||||
# Check for first line of polygon.
|
||||
#
|
||||
match = RE_POINTS_START.match(line)
|
||||
|
||||
if match is not None:
|
||||
category = match['category']
|
||||
points = re.split(r'\s+', match['rest'])
|
||||
elif points is not None:
|
||||
match = RE_POINTS.match(line)
|
||||
if match is not None:
|
||||
print(f"Already have {len(points)} points")
|
||||
category = match['category']
|
||||
points = re.split(r'\s+', match['rest'])[1:]
|
||||
continue
|
||||
|
||||
if match is not None:
|
||||
points.extend(re.split(r'\s+', line.rstrip()))
|
||||
#
|
||||
# Check for polygon line continuation.
|
||||
#
|
||||
match = RE_POINTS.match(line)
|
||||
|
||||
if match is not None:
|
||||
points.extend(re.split(r'\s+', line.rstrip())[1:])
|
||||
continue
|
||||
|
||||
#
|
||||
# If none of the previous expressions match, then treat all
|
||||
# following text as body.
|
||||
#
|
||||
area.body = line
|
||||
state = SPCOutlookParserState.BODY
|
||||
elif state == SPCOutlookParserState.BODY:
|
||||
area.body += '\n' + line
|
||||
|
||||
return area
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue