Started parsing wix-data to xml

This commit is contained in:
Jonas Linter
2025-09-27 12:15:43 +02:00
parent 0f7f1532a0
commit 553fcc7a24
4 changed files with 97 additions and 52 deletions

View File

@@ -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(