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
|
area_type = None
|
||||||
threat = None
|
threat = None
|
||||||
category = None
|
category = None
|
||||||
points = None
|
points = list()
|
||||||
|
|
||||||
for line in text.split('\n'):
|
for line in text.split('\n'):
|
||||||
if line is None:
|
if line is None:
|
||||||
|
@ -101,14 +101,14 @@ class SPCOutlookArea():
|
||||||
|
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
|
|
||||||
if line == '':
|
|
||||||
continue
|
|
||||||
|
|
||||||
if state is SPCOutlookParserState.HEADER:
|
if state is SPCOutlookParserState.HEADER:
|
||||||
|
if line == '':
|
||||||
|
continue
|
||||||
|
|
||||||
match = RE_HEADER.match(line)
|
match = RE_HEADER.match(line)
|
||||||
|
|
||||||
if match is None:
|
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'])
|
area.day = int(match['day'])
|
||||||
|
|
||||||
|
@ -148,6 +148,9 @@ class SPCOutlookArea():
|
||||||
|
|
||||||
state = SPCOutlookParserState.VALIDITY
|
state = SPCOutlookParserState.VALIDITY
|
||||||
elif state is SPCOutlookParserState.VALIDITY:
|
elif state is SPCOutlookParserState.VALIDITY:
|
||||||
|
if line == '':
|
||||||
|
continue
|
||||||
|
|
||||||
match = RE_VALIDITY.match(line)
|
match = RE_VALIDITY.match(line)
|
||||||
|
|
||||||
if match is None:
|
if match is None:
|
||||||
|
@ -194,36 +197,62 @@ class SPCOutlookArea():
|
||||||
|
|
||||||
state = SPCOutlookParserState.AREA_THREAT
|
state = SPCOutlookParserState.AREA_THREAT
|
||||||
elif state is 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}")
|
print(f"Done getting points, area type {area_type} threat {threat}")
|
||||||
|
|
||||||
threat = None
|
threat = None
|
||||||
category = None
|
category = None
|
||||||
points = None
|
points = list()
|
||||||
|
continue
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check for an area type.
|
||||||
|
#
|
||||||
match = RE_AREA_TYPE.match(line)
|
match = RE_AREA_TYPE.match(line)
|
||||||
|
|
||||||
if match is not None:
|
if match is not None:
|
||||||
area_type = match['type']
|
area_type = match['type']
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check for an area threat.
|
||||||
|
#
|
||||||
match = RE_THREAT.match(line)
|
match = RE_THREAT.match(line)
|
||||||
|
|
||||||
if match is not None:
|
if match is not None:
|
||||||
threat = match['type']
|
threat = match['type']
|
||||||
continue
|
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:
|
if match is not None:
|
||||||
category = match['category']
|
print(f"Already have {len(points)} points")
|
||||||
points = re.split(r'\s+', match['rest'])
|
category = match['category']
|
||||||
elif points is not None:
|
points = re.split(r'\s+', match['rest'])[1:]
|
||||||
match = RE_POINTS.match(line)
|
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
|
return area
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue