Started parsing wix-data to xml
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,3 +13,6 @@ wheels/
|
|||||||
|
|
||||||
# exclude ruff cache
|
# exclude ruff cache
|
||||||
.ruff_cache/
|
.ruff_cache/
|
||||||
|
|
||||||
|
# ignore test_data content but keep the folder
|
||||||
|
test_data/*
|
||||||
|
|||||||
30
output.xml
30
output.xml
@@ -1,13 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000">
|
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000">
|
||||||
<ReservationsList>
|
<ReservationsList>
|
||||||
<HotelReservation CreateDateTime="2025-09-27T07:58:55.473029+00:00" ResStatus="Requested" RoomStayReservation="true">
|
<HotelReservation CreateDateTime="2025-09-27T10:06:47.745357+00:00" ResStatus="Requested" RoomStayReservation="true">
|
||||||
<UniqueID Type="14" ID="6b34fe24ac2ff811"/>
|
<UniqueID Type="14" ID="6b34fe24ac2ff811"/>
|
||||||
<RoomStays>
|
<RoomStays>
|
||||||
<RoomStay>
|
<RoomStay>
|
||||||
<TimeSpan>
|
<TimeSpan Start="2025-10-03" End="2025-10-05"/>
|
||||||
<StartDateWindow EarliestDate="2024-10-01" LatestDate="2024-10-02"/>
|
|
||||||
</TimeSpan>
|
|
||||||
</RoomStay>
|
</RoomStay>
|
||||||
</RoomStays>
|
</RoomStays>
|
||||||
<ResGuests>
|
<ResGuests>
|
||||||
@@ -15,20 +13,16 @@
|
|||||||
<Profiles>
|
<Profiles>
|
||||||
<ProfileInfo>
|
<ProfileInfo>
|
||||||
<Profile>
|
<Profile>
|
||||||
<Customer Gender="Male" BirthDate="1980-01-01" Language="en">
|
<Customer Language="it">
|
||||||
<PersonName>
|
<PersonName>
|
||||||
<NamePrefix>Mr.</NamePrefix>
|
<NamePrefix>Familie</NamePrefix>
|
||||||
<GivenName>John</GivenName>
|
<GivenName>Miriana</GivenName>
|
||||||
<Surname>Doe</Surname>
|
<Surname>Darman</Surname>
|
||||||
</PersonName>
|
</PersonName>
|
||||||
<Telephone PhoneTechType="5" PhoneNumber="+1234567890"/>
|
<Telephone PhoneTechType="5" PhoneNumber="+39 348 443 0969"/>
|
||||||
<Telephone PhoneNumber="+0987654321"/>
|
<Email Remark="newsletter:no">miriana.m9@gmail.com</Email>
|
||||||
<Email Remark="newsletter:yes">john.doe@example.com</Email>
|
|
||||||
<Address Remark="catalog:no">
|
<Address Remark="catalog:no">
|
||||||
<AddressLine>123 Main Street</AddressLine>
|
<CountryName Code="IT"/>
|
||||||
<CityName>Anytown</CityName>
|
|
||||||
<PostalCode>12345</PostalCode>
|
|
||||||
<CountryName Code="US"/>
|
|
||||||
</Address>
|
</Address>
|
||||||
</Customer>
|
</Customer>
|
||||||
</Profile>
|
</Profile>
|
||||||
@@ -39,11 +33,11 @@
|
|||||||
<ResGlobalInfo>
|
<ResGlobalInfo>
|
||||||
<Comments>
|
<Comments>
|
||||||
<Comment Name="customer comment">
|
<Comment Name="customer comment">
|
||||||
<ListItem ListItem="1" Language="en">Landing page comment</ListItem>
|
<ListItem ListItem="1" Language="it">Landing page comment</ListItem>
|
||||||
<Text>This is a sample comment.</Text>
|
<Text>Wix form submission</Text>
|
||||||
</Comment>
|
</Comment>
|
||||||
<Comment Name="additional info">
|
<Comment Name="additional info">
|
||||||
<Text>This is a special request comment.</Text>
|
<Text>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</Text>
|
||||||
</Comment>
|
</Comment>
|
||||||
</Comments>
|
</Comments>
|
||||||
<HotelReservationIDs>
|
<HotelReservationIDs>
|
||||||
|
|||||||
@@ -20,6 +20,47 @@ from .simplified_access import (
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
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 - use None instead of object() for cleaner XML output
|
||||||
success = None
|
success = None
|
||||||
|
|
||||||
@@ -28,14 +69,11 @@ def main():
|
|||||||
type_value=ab.UniqueIdType2.VALUE_14, id="6b34fe24ac2ff811"
|
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(
|
time_span = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.RoomStays.RoomStay.TimeSpan(
|
||||||
start_date_window=start_date_window
|
start= start_date, end=end_date
|
||||||
)
|
)
|
||||||
|
|
||||||
# RoomStay with TimeSpan
|
# RoomStay with TimeSpan
|
||||||
@@ -48,30 +86,44 @@ def main():
|
|||||||
room_stay=[room_stay]
|
room_stay=[room_stay]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# CustomerData
|
||||||
|
phone_numbers = [(phone, PhoneTechType.MOBILE)] if phone else []
|
||||||
customer_data = CustomerData(
|
customer_data = CustomerData(
|
||||||
given_name="John",
|
given_name=given_name,
|
||||||
surname="Doe",
|
surname=surname,
|
||||||
name_prefix="Mr.",
|
name_prefix=name_prefix,
|
||||||
phone_numbers=[
|
phone_numbers=phone_numbers,
|
||||||
("+1234567890", PhoneTechType.MOBILE), # Phone number with type
|
email_address=email_address,
|
||||||
("+0987654321", None), # Phone number without type
|
email_newsletter=email_newsletter,
|
||||||
],
|
address_line=address_line,
|
||||||
email_address="john.doe@example.com",
|
city_name=city_name,
|
||||||
email_newsletter=True,
|
postal_code=postal_code,
|
||||||
address_line="123 Main Street",
|
country_code=country_code,
|
||||||
city_name="Anytown",
|
|
||||||
postal_code="12345",
|
|
||||||
country_code="US",
|
|
||||||
address_catalog=False,
|
address_catalog=False,
|
||||||
gender="Male",
|
gender=gender,
|
||||||
birth_date="1980-01-01",
|
birth_date=birth_date,
|
||||||
language="en",
|
language=language,
|
||||||
)
|
)
|
||||||
|
|
||||||
alpine_bits_factory = AlpineBitsFactory()
|
alpine_bits_factory = AlpineBitsFactory()
|
||||||
|
|
||||||
res_guests = alpine_bits_factory.create_res_guests(customer_data, OtaMessageType.RETRIEVE)
|
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(
|
hotel_res_id_data = HotelReservationIdData(
|
||||||
res_id_type="13",
|
res_id_type="13",
|
||||||
res_id_value=None,
|
res_id_value=None,
|
||||||
@@ -86,36 +138,32 @@ def main():
|
|||||||
hotel_reservation_id=[hotel_res_id]
|
hotel_reservation_id=[hotel_res_id]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Basic property info
|
# Basic property info (hardcoded for now)
|
||||||
basic_property_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
|
basic_property_info = ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo.BasicPropertyInfo(
|
||||||
hotel_code="123", hotel_name="Frangart Inn"
|
hotel_code="123", hotel_name="Frangart Inn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Comments from UTM fields and other info
|
||||||
|
|
||||||
|
|
||||||
comment = CommentData(
|
comment = CommentData(
|
||||||
name= ab.CommentName2.CUSTOMER_COMMENT,
|
name= ab.CommentName2.CUSTOMER_COMMENT,
|
||||||
text="This is a sample comment.",
|
text="Wix form submission",
|
||||||
list_items=[CommentListItemData(
|
list_items=[CommentListItemData(
|
||||||
value="Landing page comment",
|
value="Landing page comment",
|
||||||
language="en",
|
language=language,
|
||||||
list_item="1",
|
list_item="1",
|
||||||
)],
|
)],
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
comment2 = CommentData(
|
comment2 = CommentData(
|
||||||
name= ab.CommentName2.ADDITIONAL_INFO,
|
name= ab.CommentName2.ADDITIONAL_INFO,
|
||||||
text="This is a special request comment.",
|
text=utm_comment or "",
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
comments_data = CommentsData(comments=[comment, comment2])
|
comments_data = CommentsData(comments=[comment, comment2])
|
||||||
|
|
||||||
|
|
||||||
comments = alpine_bits_factory.create(comments_data, OtaMessageType.RETRIEVE)
|
comments = alpine_bits_factory.create(comments_data, OtaMessageType.RETRIEVE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ResGlobalInfo
|
# ResGlobalInfo
|
||||||
res_global_info = (
|
res_global_info = (
|
||||||
ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
|
ab.OtaResRetrieveRs.ReservationsList.HotelReservation.ResGlobalInfo(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ if __name__ == "__main__":
|
|||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"alpine_bits_python.api:app",
|
"alpine_bits_python.api:app",
|
||||||
host="0.0.0.0",
|
host="0.0.0.0",
|
||||||
port=8000,
|
port=8080,
|
||||||
reload=True, # Enable auto-reload during development
|
reload=True, # Enable auto-reload during development
|
||||||
log_level="info"
|
log_level="info"
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user