Add Eurostar Plus prices and NR advance fare support
- Eurostar scraper now fetches both Standard and Plus (PLUS class code) prices/seats in a single API call; each service dict gains plus_price and plus_seats fields - GWR fares scraper gains fetch_advance() which makes two sets of paginated calls (standard advance + first-class advance) and returns cheapest per departure; shared _run_pages() generator reduces duplication in fetch() - New /api/advance_fares/<station_crs>/<travel_date> endpoint returns advance fares as JSON, cached for 24 hours - Results page gains NR ticket selector (Walk-on / Std Advance / 1st Advance) and Eurostar selector (Standard / Plus); total column is JS-computed from the selected combination with cheapest/priciest highlighting - Load advance prices button fetches the API lazily; if advance fares are already cached they are embedded in the page and applied on load so the button is hidden automatically Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5583a20143
commit
89a536dfd3
8 changed files with 515 additions and 83 deletions
|
|
@ -6,16 +6,25 @@ def _gql_response(journeys: list) -> dict:
|
|||
return {'data': {'journeySearch': {'outbound': {'journeys': journeys}}}}
|
||||
|
||||
|
||||
def _journey(departs: str, arrives: str, price=None, seats=None, service_name='', carrier='ES') -> dict:
|
||||
def _journey(departs: str, arrives: str, price=None, seats=None, service_name='', carrier='ES',
|
||||
plus_price=None, plus_seats=None) -> dict:
|
||||
fares = [{
|
||||
'classOfService': {'code': 'STANDARD'},
|
||||
'prices': {'displayPrice': price},
|
||||
'seats': seats,
|
||||
'legs': [{'serviceName': service_name, 'serviceType': {'code': carrier}}]
|
||||
if service_name else [],
|
||||
}]
|
||||
if plus_price is not None or plus_seats is not None:
|
||||
fares.append({
|
||||
'classOfService': {'code': 'PLUS'},
|
||||
'prices': {'displayPrice': plus_price},
|
||||
'seats': plus_seats,
|
||||
'legs': [],
|
||||
})
|
||||
return {
|
||||
'timing': {'departureTime': departs, 'arrivalTime': arrives},
|
||||
'fares': [{
|
||||
'classOfService': {'code': 'STANDARD'},
|
||||
'prices': {'displayPrice': price},
|
||||
'seats': seats,
|
||||
'legs': [{'serviceName': service_name, 'serviceType': {'code': carrier}}]
|
||||
if service_name else [],
|
||||
}],
|
||||
'fares': fares,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -34,6 +43,27 @@ def test_parse_graphql_single_journey():
|
|||
assert s['train_number'] == 'ES 9014'
|
||||
assert s['price'] == 156.0
|
||||
assert s['seats'] == 37
|
||||
assert s['plus_price'] is None
|
||||
assert s['plus_seats'] is None
|
||||
|
||||
|
||||
def test_parse_graphql_standard_premier_price():
|
||||
data = _gql_response([_journey('09:31', '12:55', price=156, seats=37, service_name='9014',
|
||||
plus_price=220, plus_seats=12)])
|
||||
services = _parse_graphql(data, 'Paris Gare du Nord')
|
||||
assert len(services) == 1
|
||||
s = services[0]
|
||||
assert s['price'] == 156.0
|
||||
assert s['seats'] == 37
|
||||
assert s['plus_price'] == 220.0
|
||||
assert s['plus_seats'] == 12
|
||||
|
||||
|
||||
def test_parse_graphql_plus_price_none_when_not_returned():
|
||||
data = _gql_response([_journey('09:31', '12:55', price=156, seats=37)])
|
||||
services = _parse_graphql(data, 'Paris Gare du Nord')
|
||||
assert services[0]['plus_price'] is None
|
||||
assert services[0]['plus_seats'] is None
|
||||
|
||||
|
||||
def test_parse_graphql_half_pound_price():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue