From 553fcc7a245cbbcdf0d7d00e34751a4071c44d74 Mon Sep 17 00:00:00 2001 From: Jonas Linter Date: Sat, 27 Sep 2025 12:15:43 +0200 Subject: [PATCH] Started parsing wix-data to xml --- .gitignore | 3 + output.xml | 30 ++++---- src/alpine_bits_python/main.py | 114 +++++++++++++++++++++--------- src/alpine_bits_python/run_api.py | 2 +- 4 files changed, 97 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index e352048..2efd606 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ wheels/ # exclude ruff cache .ruff_cache/ + +# ignore test_data content but keep the folder +test_data/* diff --git a/output.xml b/output.xml index bcd1d09..8bc6ad3 100644 --- a/output.xml +++ b/output.xml @@ -1,13 +1,11 @@ - + - - - + @@ -15,20 +13,16 @@ - + - Mr. - John - Doe + Familie + Miriana + Darman - - - john.doe@example.com + + miriana.m9@gmail.com
- 123 Main Street - Anytown - 12345 - +
@@ -39,11 +33,11 @@ - Landing page comment - This is a sample comment. + Landing page comment + Wix form submission - This is a special request comment. + utm_Source: ig | utm_Medium: Instagram_Stories | utm_Campaign: Conversions_Hotel_Bemelmans_ITA | utm_Term: Cold_Traffic_Conversions_Hotel_Bemelmans_ITA | utm_Content: Grafik_4_Spätsommer_23.08-07.09_Landingpage_ITA diff --git a/src/alpine_bits_python/main.py b/src/alpine_bits_python/main.py index 01a8487..94cf538 100644 --- a/src/alpine_bits_python/main.py +++ b/src/alpine_bits_python/main.py @@ -20,6 +20,47 @@ from .simplified_access import ( def main(): + import json + import os + + # Load data from JSON file + json_path = os.path.join(os.path.dirname(__file__), '../../test_data/wix_test_data_20250927_070500.json') + with open(json_path, 'r', encoding='utf-8') as f: + wix_data = json.load(f) + + data = wix_data["data"]["data"] + + # Extract relevant fields + given_name = data.get("field:first_name_abae") or data.get("contact", {}).get("name", {}).get("first") + surname = data.get("field:last_name_d97c") or data.get("contact", {}).get("name", {}).get("last") + name_prefix = data.get("field:anrede") + email_address = data.get("field:email_5139") or data.get("contact", {}).get("email") + phone = data.get("field:phone_4c77") or (data.get("contact", {}).get("phones", [{}])[0].get("formattedPhone")) + email_newsletter = data.get("field:form_field_5a7b", "") != "Non selezionato" + address_line = None + city_name = None + postal_code = None + country_code = data.get("contact", {}).get("phones", [{}])[0].get("countryCode", "") or "IT" + gender = None + birth_date = None + language = data.get("contact", {}).get("locale", "en")[:2] + + # Dates + start_date = data.get("field:date_picker_a7c8") or data.get("Anreisedatum") or data.get("submissions", [{}])[1].get("value") + end_date = data.get("field:date_picker_7e65") or data.get("Abreisedatum") or data.get("submissions", [{}])[2].get("value") + + # Room/guest info + num_adults = int(data.get("field:number_7cf5") or 2) + num_children = int(data.get("field:anzahl_kinder") or 0) + children_ages = [] + for k in data.keys(): + if k.startswith("field:alter_kind_"): + try: + age = int(data[k]) + children_ages.append(age) + except Exception: + pass + # Success - use None instead of object() for cleaner XML output success = None @@ -28,14 +69,11 @@ def main(): type_value=ab.UniqueIdType2.VALUE_14, id="6b34fe24ac2ff811" ) - # TimeSpan - use the actual nested class + - start_date_window = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan.StartDateWindow( - earliest_date="2024-10-01", latest_date="2024-10-02" - ) time_span = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan( - start_date_window=start_date_window + start= start_date, end=end_date ) # RoomStay with TimeSpan @@ -48,30 +86,44 @@ def main(): room_stay=[room_stay] ) + # CustomerData + phone_numbers = [(phone, PhoneTechType.MOBILE)] if phone else [] customer_data = CustomerData( - given_name="John", - surname="Doe", - name_prefix="Mr.", - phone_numbers=[ - ("+1234567890", PhoneTechType.MOBILE), # Phone number with type - ("+0987654321", None), # Phone number without type - ], - email_address="john.doe@example.com", - email_newsletter=True, - address_line="123 Main Street", - city_name="Anytown", - postal_code="12345", - country_code="US", + given_name=given_name, + surname=surname, + name_prefix=name_prefix, + phone_numbers=phone_numbers, + email_address=email_address, + email_newsletter=email_newsletter, + address_line=address_line, + city_name=city_name, + postal_code=postal_code, + country_code=country_code, address_catalog=False, - gender="Male", - birth_date="1980-01-01", - language="en", + gender=gender, + birth_date=birth_date, + language=language, ) alpine_bits_factory = AlpineBitsFactory() - res_guests = alpine_bits_factory.create_res_guests(customer_data, OtaMessageType.RETRIEVE) + utm_fields = [ + ("utm_Source", "utm_source"), + ("utm_Medium", "utm_medium"), + ("utm_Campaign", "utm_campaign"), + ("utm_Term", "utm_term"), + ("utm_Content", "utm_content"), + ] + utm_comment_text = [] + for label, field in utm_fields: + val = data.get(f"field:{field}") or data.get(label) + if val: + utm_comment_text.append(f"{label}: {val}") + utm_comment = " | ".join(utm_comment_text) if utm_comment_text else None + + + hotel_res_id_data = HotelReservationIdData( res_id_type="13", res_id_value=None, @@ -86,36 +138,32 @@ def main(): hotel_reservation_id=[hotel_res_id] ) - # Basic property info + # Basic property info (hardcoded for now) basic_property_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo( hotel_code="123", hotel_name="Frangart Inn" ) + # Comments from UTM fields and other info + + comment = CommentData( name= ab.CommentName2.CUSTOMER_COMMENT, - text="This is a sample comment.", + text="Wix form submission", list_items=[CommentListItemData( value="Landing page comment", - language="en", + language=language, list_item="1", )], - - ) comment2 = CommentData( name= ab.CommentName2.ADDITIONAL_INFO, - text="This is a special request comment.", - + text=utm_comment or "", ) comments_data = CommentsData(comments=[comment, comment2]) - - comments = alpine_bits_factory.create(comments_data, OtaMessageType.RETRIEVE) - - # ResGlobalInfo res_global_info = ( ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo( diff --git a/src/alpine_bits_python/run_api.py b/src/alpine_bits_python/run_api.py index 75d74b7..9234936 100644 --- a/src/alpine_bits_python/run_api.py +++ b/src/alpine_bits_python/run_api.py @@ -9,7 +9,7 @@ if __name__ == "__main__": uvicorn.run( "alpine_bits_python.api:app", host="0.0.0.0", - port=8000, + port=8080, reload=True, # Enable auto-reload during development log_level="info" ) \ No newline at end of file