1
0
Fork 0

Differentiate real steps from "go through steps"

Hyperdia also lists the stations where the train goes through, and
changes line name, although you do not require to change trains

This marks them as such in both the JSON and the Markdown output.
This commit is contained in:
Luca Beltrame 2020-02-15 21:33:28 +01:00
parent e343ce2535
commit e3dba9a4b5
Signed by: einar
GPG key ID: 8DF631FD021DB0C5

View file

@ -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)