From e7695a5e49c3a3c760e26de66fa46666289d4d72 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sat, 4 Apr 2026 10:52:32 +0100 Subject: [PATCH] Drive search form dropdowns from VALID_MIN/MAX_CONNECTIONS; warn on short transfers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Index page connection time dropdowns now iterate over valid_min_connections and valid_max_connections passed from the view, so any change to the sets in app.py is reflected automatically (also adds the missing 45 min option). Add ⚠️ next to transfer times under 80 minutes in the results table; store connection_minutes in each trip dict to support the comparison. Co-Authored-By: Claude Sonnet 4.6 --- app.py | 8 +++++++- templates/index.html | 4 ++-- templates/results.html | 2 +- trip_planner.py | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 2ad3fce..2d2a2e2 100644 --- a/app.py +++ b/app.py @@ -36,7 +36,13 @@ DESTINATIONS = { @app.route('/') def index(): today = date.today().isoformat() - return render_template('index.html', destinations=DESTINATIONS, today=today) + return render_template( + 'index.html', + destinations=DESTINATIONS, + today=today, + valid_min_connections=sorted(VALID_MIN_CONNECTIONS), + valid_max_connections=sorted(VALID_MAX_CONNECTIONS), + ) VALID_MIN_CONNECTIONS = {45, 50, 60, 70, 80, 90, 100, 110, 120} diff --git a/templates/index.html b/templates/index.html index c8300a4..306fb90 100644 --- a/templates/index.html +++ b/templates/index.html @@ -47,7 +47,7 @@ Minimum connection time (Paddington → St Pancras) @@ -58,7 +58,7 @@ Maximum connection time (Paddington → St Pancras) diff --git a/templates/results.html b/templates/results.html index 9e71bbb..999fe2a 100644 --- a/templates/results.html +++ b/templates/results.html @@ -144,7 +144,7 @@
{{ row.ticket_name }} - {{ row.connection_duration }} + {{ row.connection_duration }}{% if row.connection_minutes < 80 %} ⚠️{% endif %} {{ row.depart_st_pancras }} diff --git a/trip_planner.py b/trip_planner.py index 4aa2ed2..c7e3286 100644 --- a/trip_planner.py +++ b/trip_planner.py @@ -127,6 +127,7 @@ def combine_trips( 'arrive_paddington': gwr['arrive_paddington'], 'headcode': gwr.get('headcode', ''), 'gwr_duration': _fmt_duration(int((arr_pad - dep_bri).total_seconds() / 60)), + 'connection_minutes': int((dep_stp - arr_pad).total_seconds() / 60), 'connection_duration': _fmt_duration(int((dep_stp - arr_pad).total_seconds() / 60)), 'depart_st_pancras': es['depart_st_pancras'], 'arrive_destination': es['arrive_destination'],