Improve parsing hours
This commit is contained in:
parent
f66c125691
commit
5182cdeb84
|
@ -72,16 +72,24 @@ 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:
|
||||
if "text-decoration: line-through" in h5.attrib.get("style", ""):
|
||||
self.th_arrival = hour[0]
|
||||
else:
|
||||
if "text-decoration: line-through" in h5.attrib.get("style", ""):
|
||||
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])
|
||||
|
|
Loading…
Reference in New Issue
Block a user