import random

import requests
import json
import tls_client

session = tls_client.Session(client_identifier='chrome_117', random_tls_extension_order=False)
proxy = 'http://127.0.0.1:7890'
session.proxies = {
    'http': proxy,
    'https': proxy,
}
headers = {
    "authority": "www.southwest.com",
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,ru;q=0.6",
    "cache-control": "no-cache",
    "content-type": "application/json",
    "origin": "https://www.southwest.com",
    "pragma": "no-cache",
    # "referer": "https://www.southwest.com/air/booking/select.html?int=HOMEQBOMAIR&adultPassengersCount=1&departureDate=2023-09-21&destinationAirportCode=LAX&fareType=USD&originationAirportCode=LAS&passengerType=ADULT&promoCode=&returnDate=2023-09-24&tripType=roundtrip&from=&to=&adultsCount=1&departureTimeOfDay=ALL_DAY&reset=true&returnTimeOfDay=ALL_DAY",
    # "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
    "x-api-key": "l7xx944d175ea25f4b9c903a583ea82a1c4c",
    "x-app-id": "air-booking",
    "x-channel-id": "southwest",

}

# https://www.southwest.com/assets/app/scripts/swa-common.js
headers.update(
    {"ee30zvqlwf-f": "AxhXWWONAQAAhVzvek0AvW3ZDeFxBWolQ_BP9OJGOAsKH_y_080LnVkdT_oPAVnVpg0XTuHJwH9eCOfvosJeCA==",
     "ee30zvqlwf-b": "-myduli", "ee30zvqlwf-c": "AGCSV2ONAQAATJcMa3zQPcrYhrvQHIqwi-f2VdhZklJGlVAdhmhYs0iRbyeD",
     "ee30zvqlwf-d": "ABaAhIDBCKGFgQGAAYIQgISigaIAwBGAzvpizi_33wdoWLNIkW8ng_____-Q82rrAD-P-YPcFpJ0qEbFuaKI0I0",
     "ee30zvqlwf-z": "q",
     "ee30zvqlwf-a": "4gc=iPYFqwT4dydDNh=8LHBq_MUPSLi4K_gmOvNbb7dpqWPt8FAVOUt8wU1tHSnHSYt-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9yNeG8MkUlnhMUmF8urCYJ6Y=Sf9SURJ8qS6sADLeYGfGoJPCo=3mqEIpVFT0ZhnEnb4Z7ecm8se-Cdw9K1PMpnJtfsNCoftVBLAl98LkuwV18eqkBnpSjDZdQWg2or6pHgYDrL64h_ww-ScWaprFHsOK-jEJsC_BqSZL3nybaOyZuB8aIgYwLvYnWCTzVg=kFDq65-zuybFukdu5Xq3KSfP7DLk2T127MJc6bpZwu8=7aK4GcXoK64vfF7qKiwF3j65nVjOmqjkb6yV89IYfebeb20kt-0TmXy29h5oO_spjzTtDKpVYndDP0EaKQAjT",
     "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.69"}

)
# headers.pop('xhr_url')
# headers.pop('xhr_res')
print(len(headers['ee30zvqlwf-a']))
url = "https://www.southwest.com/api/air-booking/v1/air-booking/page/air/booking/shopping"
data = {
    "adultPassengersCount": "1",
    "adultsCount": "1",
    "departureDate": "2023-12-22",
    "departureTimeOfDay": "ALL_DAY",
    "destinationAirportCode": "LAX",
    "fareType": "USD",
    "from": "",
    "int": "HOMEQBOMAIR",
    "originationAirportCode": "LAS",
    "passengerType": "ADULT",
    "promoCode": "",
    "reset": "true",
    "returnDate": "2023-08-24",
    "returnTimeOfDay": "ALL_DAY",
    "to": "",
    "tripType": "roundtrip",
    "application": "air-booking",
    "site": "southwest"
}
data = json.dumps(data, separators=(',', ':'))
for i in range(10):
    response = session.post(url, headers=headers, data=data)

    print(response.text)
    print(response)


# r = requests.post('http://ymx-lcc.unififi.com/header/add', json={
#                     'brush_fromto': 'LAS-BOS',
#                     'brush_fromdate': '2023-05-26',
#                     'brush_header': headers,
#                     'brush_proxy': f'http://user-uni003-region-us-sessid-{random.randint(1000,5000)}-sesstime-5-keep-true:q39CEBTs5A5YQXor@pr.roxlabs.cn:4600',
#                     'brush_mode': 'shopping',
#                     'brush_name': 'jstest1',
#                     'brush_type': 'cookieWN',
#                 })