Improve display of cabins list

This commit is contained in:
Edward Betts 2023-01-08 12:22:36 +00:00
parent 70db886a81
commit 944fe24662
5 changed files with 150 additions and 22 deletions

41
main.py
View file

@ -9,14 +9,14 @@ import re
from datetime import date, datetime, timedelta
from typing import Any
import dateutil.parser
import flask
import pytz
import routes
import werkzeug.exceptions
from werkzeug.debug.tbtools import get_current_traceback
from werkzeug.wrappers import Response
from ferry import ports
import ferry
from ferry.api import get_accommodations, get_prices
from ferry.read_config import ferry_config, vehicle_from_config
@ -86,22 +86,19 @@ def show_route(
"""Page showing list of prices."""
prices = get_prices(departure_port, arrival_port)
port_lookup = {code: name for name, code in ports.items()}
return flask.render_template(
"route.html",
departure_port=port_lookup[departure_port],
arrival_port=port_lookup[arrival_port],
departure_port=ferry.port_lookup[departure_port],
arrival_port=ferry.port_lookup[arrival_port],
days=prices["crossings"],
parse_date=parse_date,
)
@app.route("/")
def start() -> Response:
def start() -> Response | str:
"""Start page."""
return flask.render_template("index.html")
return flask.redirect(flask.url_for("outbound_page"))
def cabins_url(dep, arr, crossing, ticket_tier):
@ -110,8 +107,8 @@ def cabins_url(dep, arr, crossing, ticket_tier):
return flask.url_for(
"cabins",
departure_port=ports[dep],
arrival_port=ports[arr],
departure_port=ferry.ports[dep],
arrival_port=ferry.ports[arr],
departure_date=utc_dt.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
ticket_tier=ticket_tier,
)
@ -150,7 +147,13 @@ def get_prices_with_cache(
filename = cache_filename(params)
all_data = [
(dep, arr, get_prices(ports[dep], ports[arr], start, end, vehicle)["crossings"])
(
dep,
arr,
get_prices(ferry.ports[dep], ferry.ports[arr], start, end, vehicle)[
"crossings"
],
)
for dep, arr in selection
]
@ -180,7 +183,7 @@ def build_outbound(section: str) -> str:
"all_routes.html",
data=all_data,
days_until_start=get_days_until_start(),
ports=ports,
ports=ferry.ports,
parse_date=parse_date,
from_date=start,
to_date=end,
@ -232,7 +235,7 @@ def return_page() -> str:
return flask.render_template(
"all_routes.html",
data=all_data,
ports=ports,
ports=ferry.ports,
days_until_start=get_days_until_start(),
parse_date=parse_date,
from_date=start,
@ -286,22 +289,20 @@ def cabins(
if a["quantityAvailable"] > 0 and a["code"] != "RS"
# and "Inside" not in a["description"]
]
dep = dateutil.parser.isoparse(departure_date)
return flask.render_template(
"cabins.html",
port_lookup=ferry.port_lookup,
departure_port=departure_port,
arrival_port=arrival_port,
departure_date=departure_date,
departure_date=dep,
ticket_tier=ticket_tier,
accommodations=accommodations,
pet_accommodations=cabin_data["petAccommodations"],
)
@app.route("/routes")
def route_list() -> str:
"""List of routes."""
return flask.render_template("index.html", routes=routes, ports=ports)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5001)