import requests
import tls_client



def get_header():
    r = requests.post('http://ymx-lcc.unififi.com/header/borrow',json={
        "brush_type": "cookieTR",
        "brush_fromto": "aaa-bbb",
        "method": "shopping"
    })
    return r.json()

def return_header(header):
    r = requests.post('http://ymx-lcc.unififi.com/header/return',json={
        "brush_type": "cookieTR",
        "_id": header['brush_id'],
        "status": 0,
    })
    print(r.text)

def test():
    header = get_header()
    headers = header['data']['brush_header']
    brush_proxy = header['data']['brush_proxy']
    session = tls_client.Session(client_identifier='chrome_117')
    session.proxies = {
        'http': 'http://127.0.0.1:7890',
        'https': 'http://127.0.0.1:7890',
    }
    session.proxies = {
        'http': brush_proxy,
        'https': brush_proxy,
    }
    print(headers)
    url = "https://makeabooking.flyscoot.com/Book/Flight?culture=en-SG&type=oneway&dst1=HKT&ast1=TAO&dd=2023-12-15&rd=null&adt=1&chd=0&inf=0#"
    # url = "https://makeabooking.flyscoot.com/Book/Flight?culture=en-SG&type=oneway&dst1=SIN&ast1=ADL&dst2=ADL&ast2=SIN&dd=2023-12-18&rd=null&adt=1&chd=0&inf=0"
    response = session.get(url, headers=headers)
    print(response.text)

    return_header(header['data'])

if __name__ == '__main__':
    test()