From 4b8c29a8d0f32644085183300fda1acb89d305b9 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 18 Jul 2025 11:08:34 +0200 Subject: [PATCH] Update airbnb parse previous airbnb stays. --- agenda/airbnb.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/agenda/airbnb.py b/agenda/airbnb.py index 65ff5ad..dfbf3c2 100644 --- a/agenda/airbnb.py +++ b/agenda/airbnb.py @@ -73,11 +73,11 @@ def get_room_url(tree: Any) -> str | None: def get_price_from_reservation(reservation: StrDict) -> str: - price_string = reservation["payment_summary"]["subtitle"] - assert isinstance(price_string, str) + price = reservation["payment_summary"]["subtitle"] + assert isinstance(price, str) tc = "Total cost: " - assert price_string.startswith(tc) - price = price_string[len(tc) :] + if price.startswith(tc): + price = price[len(tc) :] assert price[0] == "£" return price[1:] @@ -129,7 +129,7 @@ def extract_booking_from_html(html_file: str) -> StrDict: metadata["check_out_date"], check_out_time, metadata["timezone"] ) - address = reservation["map"]["address"] + address = reservation["map"]["address"] if "map" in reservation else None if "header_action.pdp" in reservation: name = reservation["header_action.pdp"]["subtitle"] @@ -143,7 +143,6 @@ def extract_booking_from_html(html_file: str) -> StrDict: "location": location, "booking_reference": confirmation_code, "booking_url": f"https://www.airbnb.co.uk/trips/v1/reservation-details/ro/RESERVATION2_CHECKIN/{confirmation_code}", - "address": address, "country": country_code, "latitude": metadata["lat"], "longitude": metadata["lng"], @@ -154,6 +153,8 @@ def extract_booking_from_html(html_file: str) -> StrDict: "currency": "GBP", "number_of_adults": number_of_adults, } + if address: + booking["address"] = address room_url = get_room_url(tree) if room_url is not None: