Assorted cleanups
This commit is contained in:
parent
76bf0f2ddf
commit
b7fc98bae7
1 changed files with 5 additions and 5 deletions
10
hyperdia.py
10
hyperdia.py
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue