diff --git a/templates/trip_page.html b/templates/trip_page.html index 0ea5ac5..13a6c88 100644 --- a/templates/trip_page.html +++ b/templates/trip_page.html @@ -6,7 +6,7 @@ {% block style %} -{% if station_coordinates %} +{% if coordinates %} @@ -77,7 +77,7 @@ {% endfor %} - {% if station_coordinates %} + {% if coordinates %}
{% endif %} @@ -86,25 +86,41 @@ {% block scripts %} -{% if station_coordinates %} +{% if coordinates %} diff --git a/web_view.py b/web_view.py index 7c612d7..c771b0a 100755 --- a/web_view.py +++ b/web_view.py @@ -3,7 +3,6 @@ """Web page to show upcoming events.""" import inspect -import itertools import operator import os.path import sys @@ -182,8 +181,8 @@ def load_trains() -> list[StrDict]: for leg in train["legs"]: assert leg["from"] in by_name assert leg["to"] in by_name - leg["from_station"] = by_name[train["from"]] - leg["to_station"] = by_name[train["to"]] + leg["from_station"] = by_name[leg["from"]] + leg["to_station"] = by_name[leg["to"]] return trains @@ -256,8 +255,8 @@ def trip_list() -> str: ) -def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]: - """Extract and deduplicate station coordinates from trip.""" +def collect_trip_coordinates(trip: Trip) -> list[StrDict]: + """Extract and deduplicate airport and station coordinates from trip.""" stations = {} station_list = [] airports = {} @@ -279,8 +278,21 @@ def collect_station_coordinates(trip: Trip) -> list[tuple[float, float]]: stations[s["uic"]] = s return [ - (s["latitude"], s["longitude"]) - for s in itertools.chain(stations.values(), airports.values()) + { + "name": s["name"], + "type": "station", + "latitude": s["latitude"], + "longitude": s["longitude"], + } + for s in stations.values() + ] + [ + { + "name": s["name"], + "type": "airport", + "latitude": s["latitude"], + "longitude": s["longitude"], + } + for s in airports.values() ] @@ -295,13 +307,13 @@ def trip_page(start: str) -> str: if not trip: flask.abort(404) - station_coordinates = collect_station_coordinates(trip) + coordinates = collect_trip_coordinates(trip) return flask.render_template( "trip_page.html", trip=trip, today=today, - station_coordinates=station_coordinates, + coordinates=coordinates, get_country=agenda.get_country, format_list_with_ampersand=format_list_with_ampersand, )