diff --git a/app.py b/app.py index cdfa4ef..fd40f62 100644 --- a/app.py +++ b/app.py @@ -7,8 +7,7 @@ from datetime import date, timedelta from cache import get_cached, set_cached import scraper.eurostar as eurostar_scraper import scraper.realtime_trains as rtt_scraper -from trip_planner import combine_trips, find_unreachable_morning_eurostars -from scraper.eurostar import fetch_prices as fetch_eurostar_prices +from trip_planner import combine_trips RTT_PADDINGTON_URL = ( "https://www.realtimetrains.co.uk/search/detailed/" @@ -81,12 +80,10 @@ def results(slug, travel_date): rtt_cache_key = f"rtt_{travel_date}" es_cache_key = f"eurostar_{travel_date}_{destination}" - prices_cache_key = f"eurostar_prices_{travel_date}_{destination}" cached_rtt = get_cached(rtt_cache_key) cached_es = get_cached(es_cache_key) - cached_prices = get_cached(prices_cache_key, ttl=24 * 3600) - from_cache = bool(cached_rtt and cached_es and cached_prices) + from_cache = bool(cached_rtt and cached_es) error = None @@ -111,44 +108,8 @@ def results(slug, travel_date): msg = f"Could not fetch Eurostar times: {e}" error = f"{error}; {msg}" if error else msg - if cached_prices: - eurostar_prices = cached_prices - else: - try: - eurostar_prices = fetch_eurostar_prices(destination, travel_date) - set_cached(prices_cache_key, eurostar_prices) - except Exception as e: - eurostar_prices = {} - msg = f"Could not fetch Eurostar prices: {e}" - error = f"{error}; {msg}" if error else msg - trips = combine_trips(gwr_trains, eurostar_trains, travel_date, min_connection, max_connection) - # Annotate each trip with Eurostar Standard price and total cost - for trip in trips: - es_price = eurostar_prices.get(trip['depart_st_pancras']) - trip['eurostar_price'] = es_price - if es_price is not None: - trip['total_price'] = trip['ticket_price'] + es_price - else: - trip['total_price'] = None - - unreachable_morning_services = find_unreachable_morning_eurostars( - gwr_trains, - eurostar_trains, - travel_date, - min_connection, - max_connection, - ) - for svc in unreachable_morning_services: - svc['eurostar_price'] = eurostar_prices.get(svc['depart_st_pancras']) - - result_rows = sorted( - [{'row_type': 'trip', **trip} for trip in trips] - + [{'row_type': 'unreachable', **service} for service in unreachable_morning_services], - key=lambda row: row['depart_st_pancras'], - ) - dt = date.fromisoformat(travel_date) prev_date = (dt - timedelta(days=1)).isoformat() next_date = (dt + timedelta(days=1)).isoformat() @@ -160,8 +121,6 @@ def results(slug, travel_date): return render_template( 'results.html', trips=trips, - result_rows=result_rows, - unreachable_morning_services=unreachable_morning_services, destinations=DESTINATIONS, destination=destination, travel_date=travel_date, diff --git a/cache.py b/cache.py index 2e82500..668103f 100644 --- a/cache.py +++ b/cache.py @@ -1,6 +1,5 @@ import json import os -import time CACHE_DIR = os.path.join(os.path.dirname(__file__), 'cache') @@ -10,13 +9,10 @@ def _cache_path(key: str) -> str: return os.path.join(CACHE_DIR, f"{safe_key}.json") -def get_cached(key: str, ttl: int | None = None): - """Return cached data, or None if missing or older than ttl seconds.""" +def get_cached(key: str): path = _cache_path(key) if not os.path.exists(path): return None - if ttl is not None and time.time() - os.path.getmtime(path) > ttl: - return None with open(path) as f: return json.load(f) diff --git a/scraper/eurostar.py b/scraper/eurostar.py index 8ae5129..7e9f3e7 100644 --- a/scraper/eurostar.py +++ b/scraper/eurostar.py @@ -1,7 +1,7 @@ """ -Scrape Eurostar timetable via httpx and fetch prices via the GraphQL API. +Scrape Eurostar timetable via httpx. -Timetable: route-specific pages are Next.js SSR — all departure data is +The route-specific timetable pages are Next.js SSR — all departure data is embedded in