Improve parsing hours

master
blallo 2022-08-25 21:35:25 +02:00
parent f66c125691
commit 5182cdeb84
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
1 changed files with 16 additions and 8 deletions

View File

@ -72,17 +72,25 @@ class Details(object):
origin: T.Optional[T.Text] = None
status: Status = Status.UNKNOWN
def maybe_parse_hour(self, h5: et._ElementTree) -> None:
def maybe_parse_hour_th(self, h5: et._ElementTree) -> None:
"""
This function fills the fileds related to the arrival hour,
This function fills the fileds related to the theoric arrival hour,
if the input matches some heuristics.
"""
hour = TIME_RE.findall(h5.text)
if len(hour) == 1:
self.th_arrival = hour[0]
if "text-decoration: line-through" in h5.attrib.get("style", ""):
self.th_arrival = hour[0]
else:
self.real_arrival = hour[0]
self.real_arrival = None
def maybe_parse_hour_real(self, h5: et._ElementTree) -> None:
"""
This function fills the fileds related to the theoric arrival hour,
if the input matches some heuristics.
"""
hour = TIME_RE.findall(h5.text)
if len(hour) == 1:
self.real_arrival = hour[0]
def maybe_parse_code(self, h5: et._ElementTree) -> None:
"""
@ -145,13 +153,13 @@ def get_details(table_entry: et._ElementTree, debug: bool = False) -> Details:
d = Details()
if len(res) == 5:
d.maybe_parse_hour(res[0])
d.maybe_parse_hour_th(res[0])
d.maybe_parse_code(res[1])
d.maybe_parse_airport(res[2])
d.maybe_parse_status(res[3])
elif len(res) == 6:
d.maybe_parse_hour(res[0])
d.maybe_parse_hour(res[1])
d.maybe_parse_hour_th(res[0])
d.maybe_parse_hour_real(res[1])
d.maybe_parse_code(res[2])
d.maybe_parse_airport(res[3])
d.maybe_parse_status(res[4])