parent
ad47f291f8
commit
2744f67987
3 changed files with 106 additions and 2 deletions
33
web_view.py
33
web_view.py
|
|
@ -170,8 +170,24 @@ def build_trip_list() -> list[Trip]:
|
|||
|
||||
data_dir = app.config["PERSONAL_DATA"]
|
||||
|
||||
stations = travel.parse_yaml("stations", data_dir)
|
||||
by_name = {station["name"]: station for station in stations}
|
||||
|
||||
trains = load_travel("train")
|
||||
for train in trains:
|
||||
assert train["from"] in by_name
|
||||
assert train["to"] in by_name
|
||||
train["from_station"] = by_name[train["from"]]
|
||||
train["to_station"] = by_name[train["to"]]
|
||||
|
||||
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"]]
|
||||
|
||||
travel_items = sorted(
|
||||
load_travel("flight") + load_travel("train"), key=operator.itemgetter("depart")
|
||||
load_travel("flight") + trains, key=operator.itemgetter("depart")
|
||||
)
|
||||
|
||||
data = {
|
||||
|
|
@ -219,5 +235,20 @@ def trip_list() -> str:
|
|||
)
|
||||
|
||||
|
||||
@app.route("/trip/<start>")
|
||||
def trip_page(start: str) -> str:
|
||||
trip_list = build_trip_list()
|
||||
today = date.today()
|
||||
|
||||
trip = next((trip for trip in trip_list if trip.start.isoformat() == start), None)
|
||||
return flask.render_template(
|
||||
"trip_page.html",
|
||||
trip=trip,
|
||||
today=today,
|
||||
get_country=agenda.get_country,
|
||||
format_list_with_ampersand=format_list_with_ampersand,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue