Show Eurostar Standard prices and total journey cost on results page
Fetches prices via the site-api.eurostar.com GraphQL gateway (NewBookingSearch operation, discovered with Playwright). Adds fetch_prices() to scraper/eurostar.py using requests, caches results, annotates each trip with eurostar_price and total_price, and shows an ES Std column plus total cost (duration + price) in the results table. The Transfer column is hidden on small screens for mobile usability. Closes #4 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
804fcedfad
commit
0dee942e16
4 changed files with 191 additions and 12 deletions
|
|
@ -6,7 +6,7 @@ def _client():
|
|||
return app_module.app.test_client()
|
||||
|
||||
|
||||
def _stub_data(monkeypatch):
|
||||
def _stub_data(monkeypatch, prices=None):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(
|
||||
|
|
@ -33,6 +33,8 @@ def _stub_data(monkeypatch):
|
|||
'timetable_url',
|
||||
lambda destination: f'https://example.test/{destination.lower().replace(" ", "-")}',
|
||||
)
|
||||
_prices = prices if prices is not None else {}
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: _prices)
|
||||
|
||||
|
||||
def test_index_shows_fixed_departure_and_destination_radios():
|
||||
|
|
@ -94,6 +96,7 @@ def test_results_title_and_social_meta_include_destination(monkeypatch):
|
|||
def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
@ -165,6 +168,7 @@ def test_results_marks_trips_within_five_minutes_of_fastest_and_slowest(monkeypa
|
|||
def test_results_shows_unreachable_morning_eurostar_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
@ -215,9 +219,23 @@ def test_results_shows_unreachable_morning_eurostar_services(monkeypatch):
|
|||
assert html.index('09:30') < html.index('10:15')
|
||||
|
||||
|
||||
def test_results_shows_eurostar_price_and_total(monkeypatch):
|
||||
# 07:00 on Friday 2026-04-10 → Anytime £138.70 (weekday, 05:05–08:25 window)
|
||||
_stub_data(monkeypatch, prices={'10:01': 59})
|
||||
client = _client()
|
||||
|
||||
resp = client.get('/results/paris/2026-04-10?min_connection=60&max_connection=120')
|
||||
html = resp.get_data(as_text=True)
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert '£59' in html # Eurostar Standard price
|
||||
assert '£197.70' in html # Anytime £138.70 + ES £59
|
||||
|
||||
|
||||
def test_results_can_show_only_unreachable_morning_services(monkeypatch):
|
||||
monkeypatch.setattr(app_module, 'get_cached', lambda key: None)
|
||||
monkeypatch.setattr(app_module, 'set_cached', lambda key, data: None)
|
||||
monkeypatch.setattr(app_module, 'fetch_eurostar_prices', lambda dest, date: {})
|
||||
monkeypatch.setattr(
|
||||
app_module.rtt_scraper,
|
||||
'fetch',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue