Improve parsing hours

This commit is contained in:
sfigato 2022-08-25 21:35:25 +02:00
parent f66c125691
commit 5182cdeb84
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

View File

@ -72,17 +72,25 @@ class Details(object):
origin: T.Optional[T.Text] = None origin: T.Optional[T.Text] = None
status: Status = Status.UNKNOWN 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. if the input matches some heuristics.
""" """
hour = TIME_RE.findall(h5.text) hour = TIME_RE.findall(h5.text)
if len(hour) == 1: if len(hour) == 1:
self.th_arrival = hour[0]
if "text-decoration: line-through" in h5.attrib.get("style", ""): if "text-decoration: line-through" in h5.attrib.get("style", ""):
self.th_arrival = hour[0] self.real_arrival = None
else:
self.real_arrival = hour[0] 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: 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() d = Details()
if len(res) == 5: 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_code(res[1])
d.maybe_parse_airport(res[2]) d.maybe_parse_airport(res[2])
d.maybe_parse_status(res[3]) d.maybe_parse_status(res[3])
elif len(res) == 6: elif len(res) == 6:
d.maybe_parse_hour(res[0]) d.maybe_parse_hour_th(res[0])
d.maybe_parse_hour(res[1]) d.maybe_parse_hour_real(res[1])
d.maybe_parse_code(res[2]) d.maybe_parse_code(res[2])
d.maybe_parse_airport(res[3]) d.maybe_parse_airport(res[3])
d.maybe_parse_status(res[4]) d.maybe_parse_status(res[4])