1
0
Fork 0

Assorted cleanups

This commit is contained in:
Luca Beltrame 2020-01-06 04:31:20 +01:00
parent 76bf0f2ddf
commit b7fc98bae7
Signed by: einar
GPG key ID: 8DF631FD021DB0C5

View file

@ -193,14 +193,13 @@ def parse_hyperdia_table(soup, year, month, day):
data = list()
previous = 0
# Skip the heading and the row immediately afterwards (commuter pass)
for group in mlt.windowed(soup.find_all("tr")[2:], n=3, step=2):
# Groups of 3 elements:
# First row: start station (time in first column, station in column 3)
# Second row: train information (duration in column 1, name in column 3)
# Second row: train information (duration in column 1,
# name in column 3)
# Third row: arrival time(s) (same format as first row)
# Times might be repeated more than once if it's a transfer
@ -298,7 +297,7 @@ def trip_summary(trip: HyperdiaTrip) -> str:
table = tabulate(table, tablefmt="github", headers="keys", showindex=False)
summary = (f"Total time: {trip.total_time} minutes,"
f" Total distance: {trip.total_distance},"
f" Total distance: {trip.total_distance} Km,"
f" Total cost: {trip.total_cost} JPY")
return table + "\n\n" + summary + "\n\n"
@ -316,9 +315,10 @@ def hyperdia_search(start_station: str, end_station: str, hour: int,
soup = BeautifulSoup(raw_result.text, "html.parser")
results = parse_hyperdia_html(soup, year=year, month=month, day=day)
for trip in results:
for index, trip in enumerate(results, start=1):
if output_type == "md":
print(f"#### Route {index}", end="\n\n")
print(trip_summary(trip))
elif output_type == "json":
table = convert_trip_to_table(trip)