import random
import time
import requests
import json

headers = {
    "Host": "jbrest.jetblue.com",
    "application-channel": "Desktop_Web",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-ch-ua-mobile": "?0",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
    "booking-application-type": "NGB",
    "content-type": "application/json",
    "accept": "application/json",
    "api-version": "v3",
    "origin": "https://www.jetblue.com",
    "sec-fetch-site": "same-site",
    "sec-fetch-mode": "cors",
    "sec-fetch-dest": "empty",
    "referer": "https://www.jetblue.com/booking/flights?from=LAS&to=BOS&depart=2023-07-10&isMultiCity=false&noOfRoute=1&lang=en&adults=1&children=0&infants=0&sharedMarket=false&roundTripFaresFlag=false&usePoints=false",
    "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"
}
for i in range(100):

    t1 = time.time()
    # r = requests.get('http://127.0.0.1:5000/getinfo').json()['message']
    r = requests.get('http://127.0.0.1:3001').json()
    print(time.time() - t1,r)
  #   r =   {
  #   "x-1itxwo9i-a": "F7Pgtv2oFJ6SRuiVu1hHGyVjT-E9519oQfgqVh4t7nDGry-oz_jYCRNHUfHRa5UEuU_NCnLpA1UAxW1qJ15de9rk3vXe7e9fliEH2x_f29j_-yESHK-kqhqP47HxOQqYor7JAwTlSZCRVps8dD-Sshe-kxmGeWG==sd1gfTtXb5oOW5innE_63r=6y37msgHgbZsKsr3m-Nqrg8Gs_2zZnjo3fJbU8eOViydixp9pZbueCL5AuZmCx-0Ug_Y8Z12hfhoVKQ2k8sWUWMNYbn1b7___KrGD_6VdHnekp6W0RERVtsILg92QqEg4HZ0=jDX6vAzyNdvzYVfvMYi5MarM1Y=MulNJIyOk9pabwUjA05dTVl_8vQb0YW=QCzLPrykflJmh38xJl__AJ-rMzn86-LxO4WKkE7z0Xig92=p6LyRjUymVqVqG2ibJAHUuEtEUDB947ansxUMnECeDlOOYQdY4ugI5wg4hS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lXQ3pG4j=lJ8=ovKSFQ_qSooL06-zk5oXJxe9u1Q1X5wKkE6iVEDWPl_EWd93MuVeheO2h7asXj3hzXsmXqG2G6r6bZPQhFW5I1_qmiOsD=hSfH8p7K5FPLTY=yaVDWSGHVWpkyt9CdvwE_aOiDwaCUT=tSqAOvFd6s6nj4__RavtRxtFL",
  #   "x-1itxwo9i-b": "qi0wsc",
  #   "x-1itxwo9i-c": "AEASLFKIAQAAdHv22v9hQ7HEhomgqgCgqzMhv-7h3Wivo3sNSYlTTGjk4QJh",
  #   "x-1itxwo9i-d": "ABaAhIjBCKHFgQGAAYIQgISi0aIA5JmBzvpDzz8AiVNMaOThAmEAAAAAH29cNgBzkpfthkGqgU6X0kPmJ3sq",
  #   "x-1itxwo9i-f": "A_hnLlKIAQAAx4PMly6tJ4mWsxWi_E8mIiwAt0BDrYdxTCXXD7gMu06EQeEsAS0rIPCucn0ewH9eCOfvosJeCA==",
  #   "x-1itxwo9i-z": "q"
  # }

    headers.update(r)
    print(len(headers['x-1itxwo9i-a']))
    url = "https://jbrest.jetblue.com/lfs-rwb/outboundLFS"
    data = {
        "tripType": "oneWay",
        "from": "LAS",
        "to": "BOS",
        "depart": "2023-07-10",
        "cabin": "economy",
        "refundable": False,
        "dates": {
            "before": "3",
            "after": "3"
        },
        "pax": {
            "ADT": 1,
            "CHD": 0,
            "INF": 0,
            "UNN": 0
        },
        "redempoint": False,
        "pointsBreakup": {
            "option": "",
            "value": 0
        },
        "isMultiCity": False,
        "isDomestic": False
    }
    proxy = f'http://unfflcc:76cc14-47b8dd-1f8ace-827836-0c740e@usa.rotating.proxyrack.net:{int(random.randint(10000,11149))}'
    proxy = 'http://user-unifflcc-region-us:q39CEBTs5A5YQXor@pr.roxlabs.cn:4600'
    print(proxy)
    response = requests.post(url, headers=headers, json=data, proxies={
        'http':proxy,
        'https':proxy,
    })

    print(response.text)
    if response.status_code == 200:

        # proxy = requests.post('http://ymx-lcc.unififi.com/proxy/get-proxy', json={
        #     'type':'headerB6'
        # })

        uri = 'http://lcc.unififi.com/header/add'
        r = requests.post(uri, json={
            'brush_fromto': 'LAS-BOS',
            'brush_fromdate': '2023-05-22',
            'brush_header': headers,
            'brush_proxy':proxy,
            'brush_mode':'shopping',
            'brush_name':'js',
            'brush_type':'headerB6',
        })
        print(r.text)
