diff --git a/hyperdia.py b/hyperdia.py index 4425abb..63d165f 100755 --- a/hyperdia.py +++ b/hyperdia.py @@ -75,6 +75,7 @@ class HyperdiaStep: duration: Optional[str] = None train_name: Optional[str] = None is_transfer: Optional[bool] = False + go_through: Optional[bool] = False start_track_number: Optional[int] = None end_track_number: Optional[int] = None @@ -112,6 +113,7 @@ def _serialize(trip: HyperdiaTrip) -> dict: subdict["duration"] = step.duration subdict["train_name"] = step.train_name subdict["is_transfer"] = step.is_transfer + subdict["go_through"] = step.go_through subdict["start_track_number"] = step.start_track_number subdict["end_track_number"] = step.end_track_number @@ -237,6 +239,7 @@ def parse_hyperdia_table(soup, year, month, day): data = list() previous_is_direct = False + go_through = False # Skip the heading and the row immediately afterwards (commuter pass) @@ -259,9 +262,6 @@ def parse_hyperdia_table(soup, year, month, day): direct_connection = enddata[1].next_element.get("src") - if direct_connection is not None and "icon_choku.gif" in direct_connection: - previous_is_direct = True - # Second span in the station name column contains the track number # if applicable (if not, it's empty) start_track_number = parse_track_number(startdata[2]) @@ -269,7 +269,15 @@ def parse_hyperdia_table(soup, year, month, day): start_station_time = parse_station_time(startdata[0], year, month, day, start=True) - train_name = parse_train_name(traindata) + if previous_is_direct: + train_name = "Line name change, train goes through" + previous_is_direct = False + go_through = True + else: + train_name = parse_train_name(traindata) + + if direct_connection is not None and "icon_choku.gif" in direct_connection: + previous_is_direct = True end_station_name = list(enddata[2].stripped_strings)[0] end_station_time = parse_station_time(enddata[0], year, month, day, @@ -287,7 +295,10 @@ def parse_hyperdia_table(soup, year, month, day): is_transfer=is_transfer, duration=duration, start_track_number=start_track_number, - end_track_number=end_track_number) + end_track_number=end_track_number, + go_through=go_through) + + go_through = False data.append(entry)