This commit is contained in:
Edward Betts 2023-04-16 19:56:26 +01:00
parent c26383c9c0
commit a5195cba1a
7 changed files with 263 additions and 71 deletions

View file

@ -7,6 +7,9 @@ import requests
from . import Vehicle
api_root_url = "https://www.brittany-ferries.co.uk/api/ferry/v1/"
ua = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0"
headers = {"User-Agent": ua}
class VehicleDict(TypedDict):
@ -36,14 +39,16 @@ def get_prices(
from_date: str,
to_date: str,
vehicle: Vehicle,
adults: int = 2,
small_dogs: int = 1,
) -> dict[str, Any]:
"""Call Brittany Ferries API to get details of crossings."""
url = api_root_url + "crossing/prices"
post_data = {
"bookingReference": None,
"pets": {"smallDogs": 1, "largeDogs": 0, "cats": 0},
"passengers": {"adults": 2, "children": 0, "infants": 0},
"pets": {"smallDogs": small_dogs, "largeDogs": 0, "cats": 0},
"passengers": {"adults": adults, "children": 0, "infants": 0},
"vehicle": vehicle_dict(vehicle),
"departurePort": departure_port,
"arrivalPort": arrival_port,
@ -53,7 +58,7 @@ def get_prices(
"toDate": f"{to_date}T23:59:59",
}
r = requests.post(url, json=post_data)
r = requests.post(url, json=post_data, headers=headers)
data: dict[str, Any] = r.json()
return data
@ -82,5 +87,7 @@ def get_accommodations(
"offerType": "NONE",
}
json_data: dict[str, Any] = requests.post(url, json=post_data).json()
json_data: dict[str, Any] = requests.post(
url, json=post_data, headers=headers
).json()
return json_data