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": "-9zvuwt", "ee30zvqlwf-c": "AGCSV2ONAQAATJcMa3zQPcrYhrvQHIqwi-f2VdhZklJGlVAdhmhYs0iRbyeD",
     "ee30zvqlwf-d": "ABaAhIDBCKGFgQGAAYIQgISigaIAwBGAzvpizi_33wdoWLNIkW8ng_____-Q82rrAD-P-YPcFpJ0qEbFuaKI0I0",
     "ee30zvqlwf-z": "q",
     "ee30zvqlwf-a": "ZMIR_iRvJjr_p-Cyf-kSuLEY=IBUvnw5-Kan42kpGIMlhL6-zNO-TAQy6iCnOdD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F1Ri0u7Wrcae=eHjcqhw7CsFEaR8_7qIOK3qc=JQ7NYoyurZbdNRs2dYdlhrNv801Y_UXVUaNBbbF8qPTmVBvdLtc3Ht2sdAf0YUgdKM=Zi2VTvWj1T-0BULlsPa6ysDOhasvsUtRcXz5dt-5HbBOFQ2ZjNnY1zhbG0LvjoNVr2SLeW51NWLzrfZ7nMtD47z_=k6yJ8yDKBGG7vbFQOKBtAa88AeqVJtbTvr33pzAftAkMUD1nZaz6MtR7IvQ1Flwg3kjeHUs8l9iPM1-w25e8WYlTyb=DPzQtoc8Ny6IinlZZ-lXazQqzoVPbPTJLEDQ5mbB8=_cb",
     "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',
#                 })