# -!- coding: utf-8 -!-import requestsimport jsonimport reimport timedef get_flight(parameter):# {"success": false, "msg": "很抱歉,您访问的太快了,休息一下吧,或者登录您的途牛帐号继续访问。", "errorCode": 179991, "atd": null, "data": null}parameter = json.loads(parameter)dep_code = parameter['dep_code']arr_code = parameter['arr_code']fromDate = parameter['fromDate']urls = '{"systemId":52,"pollTag":0,"channelCount":0,"adultQuantity":1,"childQuantity":0,"babyQuantity":0,"supportBlack":true,"segmentList":[{"dCityIataCode":"BJS","aCityIataCode":"SHA","departDate":"-09-01"}],"rph":0,"hackersFlightNos":null}'urls_dict = json.loads(urls)urls_dict['segmentList'][0]['dCityIataCode'] = dep_codeurls_dict['segmentList'][0]['aCityIataCode'] = arr_codeurls_dict['segmentList'][0]['departDate'] = fromDateurls = json.dumps(urls_dict)url = 'https://flight-/wzt/flight/v1/listFlight?data=' + urls + '&_=1566269494525'headers = {'Sec-Fetch-Mode': "no-cors",'Referer': "/domestic/list/BJS_SHA_ST_1_0_0/?start=-09-01",'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",'Accept': "*/*",'Cache-Control': "no-cache",'Host': "flight-",'Cookie': "OLBSESSID=s467csiveuugroeca6n412lcr4; isLogined=true; p_phone_400=4007-999-999; p_phone_level=0; p_global_phone=%2B0086-25-8685-9999; tuniuuser_citycode=MjAw",'Accept-Encoding': "gzip, deflate",'Connection': "keep-alive",'cache-control': "no-cache"}response = requests.request("GET", url, headers=headers, verify=False).json()# if response["msg"] == "很抱歉,您访问的太快了,休息一下吧,或者登录您的途牛帐号继续访问。":try:query_id = response["data"]["queryId"]except:response = requests.request("GET", url, headers=headers, verify=False).json()query_id = response["data"]["queryId"]# print(query_id)return query_iddef get_vendorid(queryId, parameter):parameter = json.loads(parameter)urls = '{"queryId":"Y2l0eUtleXM9QkpTLVNIQSxkZXBhcnR1cmVEYXRlPTIwMTktMDktMDEsZGVwYXJ0dXJlRGF0ZXM9MCxwYXNzZW5nZXJRdWFudGl0eT0xIzAjMCMwLHBoeXNpY2FsQ2FiaW49bnVsbA==","systemId":52,"flightNos":"HU7603"}'urls_dict = json.loads(urls)urls_dict['queryId'] = queryIdurls_dict["flightNos"] = parameter['data']["routing"]["fromSegments"][0]["flightNumber"]urls = json.dumps(urls_dict)url = 'https://flight-/wzt/flight/v2/multiCabinDetails?' + urls + '&_=1566268642667'headers = {'Sec-Fetch-Mode': "no-cors",'Referer': "/domestic/list/NKG_CGO_ST_1_0_0/?start=-08-21",'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",'Accept': "*/*",'Cache-Control': "no-cache",'Postman-Token': "532e624f-0549-484c-bad8-091da95edb05,8aaccc88-bf02-43e4-ace3-bddae140cd87",'Host': "flight-",'Cookie': "tuniu_partner=MTAxLDAsLDlmZDgyZThjYTZkNGMwMTlmZTUyNzdlYjJmNTcxYzQ1",'Accept-Encoding': "gzip, deflate",'Connection': "keep-alive",'cache-control': "no-cache"}response = requests.request("GET", url, headers=headers, verify=False).json()# print(2)# print(json.dumps(response))return response# 在上一步之后写一个函数,来判断具体的仓位,获取相应的价格等等信息def get_price(parameter, vebdorId):parameter = json.loads(parameter)cabinPrices = vebdorId["data"]["productCategorys"][0]["cabinPrices"]# print(cabinPrices)cobinList = []for cabinPice in cabinPrices:# print(cabinPice)if cabinPice["priceJourneyCabinList"][0]["priceFlightCabinList"][0]["cabinCode"] == \parameter["data"]["routing"]["fromSegments"][0]["cabin"] \and cabinPice["priceJourneyCabinList"][0]["priceFlightCabinList"][0]["cabinClass"] == \parameter["data"]["routing"]["fromSegments"][0]["cabinGrade"]:cobinList.append(cabinPice)return cobinList[0]else:return {"aduDivideBaby": "未查询到相应座位"}def check_price(parameter, queryId, vebdorId, cobin):url = "https://flight-/wzt/flight/check/v1/checkPrice"# print(json.dumps(cobin))parameter = json.loads(parameter)payload = '''{"distributeId":"","type":3,"checkID":"","flightId":"0ceaac98f04341409fa6d9023feb9858","systemId":"52","vendorId":"1","cabinCodes":"L","priceInfoId":"","specVendorId":"","ruleCode":"130","queryId":"Y2l0eUtleXM9QkpTLVNIQSxkZXBhcnR1cmVEYXRlPTIwMTktMDktMDEsZGVwYXJ0dXJlRGF0ZXM9MCxwYXNzZW5nZXJRdWFudGl0eT0xIzAjMCMwLHBoeXNpY2FsQ2FiaW49bnVsbA==","flightNos":"HU7603","gmjc":null,"fareBreakdownList":[{"baseFare":1010,"airportTax":50,"fuleTax":0,"adultQuantity":1,"childQuantity":0,"babyQuantity":0,"gmjcQuantity":0},{"baseFare":1010,"airportTax":50,"fuleTax":0,"adultQuantity":0,"childQuantity":1,"babyQuantity":0,"gmjcQuantity":0}]}'''payload_dict = json.loads(payload)payload_dict["queryId"] = queryIdpayload_dict['flightId'] = vebdorId["data"]["fareList"][0]["flightId"]payload_dict["vendorId"] = cobin['vendorId']payload_dict['cabinCodes'] = cobin['priceJourneyCabinList'][0]['priceFlightCabinList'][0]['cabinCode']payload_dict['ruleCode'] = cobin['prodClassific']['ruleCode']payload_dict['flightNos'] = parameter['data']["routing"]["fromSegments"][0]["flightNumber"]fareBreakdownList = []for fareBreakdown in cobin['fareBreakdownList']:# if fareBreakdown['psgType'] == "INF":#del fareBreakdownfaredict = {}faredict['baseFare'] = fareBreakdown['baseFare']faredict['airportTax'] = fareBreakdown['airportTax']faredict['fuleTax'] = fareBreakdown['fuleTax']faredict['adultQuantity'] = 0faredict['childQuantity'] = 0faredict['babyQuantity'] = 0faredict['gmjcQuantity'] = 0fareBreakdownList.append(faredict)a = len(fareBreakdownList)if a >= 2:fareBreakdownList[0]['adultQuantity'] = cobin['priceJourneyCabinList'][0]['priceFlightCabinList'][0]['specCabinStatus']fareBreakdownList[1]['childQuantity'] = cobin['priceJourneyCabinList'][0]['priceFlightCabinList'][0]['specCabinStatus']payload_dict["fareBreakdownList"] = fareBreakdownListpayload = json.dumps(payload_dict)# print(payload)headers = {'Accept': "application/json, text/javascript, */*; q=0.01",'Referer': "/domestic/book/?systemId=52&vendorId=1&cabinCodes=L&priceInfoId=&specVendorId=&ruleCode=130&queryId=Y2l0eUtleXM9TktHLUZPQyxkZXBhcnR1cmVEYXRlPTIwMTktMDgtMjEsZGVwYXJ0dXJlRGF0ZXM9MCxwYXNzZW5nZXJRdWFudGl0eT0xIzAjMCMwLHBoeXNpY2FsQ2FiaW49bnVsbA%3D%3D&flightNos=CZ5019",'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",'Sec-Fetch-Mode': "cors",'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8",'Cache-Control': "no-cache",'Host': "flight-",'Cookie': "tuniu_partner=MTAxLDAsLDlmZDgyZThjYTZkNGMwMTlmZTUyNzdlYjJmNTcxYzQ1",'Accept-Encoding': "gzip, deflate",'Content-Length': "914",'Connection': "keep-alive",'cache-control': "no-cache"}response = requests.request("POST", url, data=payload, headers=headers).json()# print(response)return responsedef save_order(parameter, queryId, vebdorId, checkprice, cobin):url = "https://flight-/wzt/flight/order/v1/saveOrder"# querystring = {"referer": ""}parameter = json.loads(parameter)payload = '''{"bif":{"intel":0},"common":{"commentFlag":0,"voucherType":5,"source":3,"level":0,"orderFlightType":1},"flightInfo":{"vendorId":"1","mainAirCom":"HU","flightNos":"HU7698","checkID":"15663734883128d1052e4-98a2-4d6a-93b3-4eaf32f441e2","queryId":"Y2l0eUtleXM9TktHLVNZWCxkZXBhcnR1cmVEYXRlPTIwMTktMDgtMjIsZGVwYXJ0dXJlRGF0ZXM9MCxwYXNzZW5nZXJRdWFudGl0eT0xIzAjMCMwLHBoeXNpY2FsQ2FiaW49bnVsbA==","cabinCodes":"Y","cabinClasses":"Y","priceInfoId":"","specVendorId":"","flightId":"ecfda8a98bc2488f9f609bde84673f5f","adultSeatNum":3,"childSeatNum":3,"isShareFlight":0,"isPackageOrder":0},"touristList":[{"name":"高治龙","firstname":"","lastname":"","psptType":1,"psptId":"41272419911002255X","country":"0086","birthday":"1991-10-02","touristType":1,"tel":"17316092102","intlCode":"0086","index":0}],"requirement":{"startCityCode":1060,"desCityCode":1418,"startDate":"-09-01","departureDate":"-09-01","backDate":"-09-01"},"priceDetail":{"adultQuantity":1,"childQuantity":0,"adultPrice":,"adultBasePrice":1960,"adultTax":50,"childPrice":1030,"childBasePrice":980,"childTax":50,"price":,"adultFuel":0,"childFuel":0,"fullPrice":1960},"contactList":[{"name":"高治龙","tel":"17316093203","areaCode":"0086"}],"armFlights":[{"flightNo":"HU7698","vendorId":"1","departDate":"-08-22","flyTimeStart":"11:50","flyTimeEnd":"14:50","orgCityName":"南京","dstCityName":"三亚","airComIata":"HU","airComName":"海南航空","orgAirportCode":"NKG","dstAirportCode":"SYX"}],"categoryMap":null,"qtzList":null,"promotionList":null,"delivery":null,"invoiceList":null,"activityList":null,"sessionId":null}'''.encode()payload_dict = json.loads(payload)touristList = []a = 0b = 0c = 0for tourist in parameter['data']['passengers']:userInfo = {}userInfo['name'] = tourist['name']userInfo['psptType'] = 1if tourist['ageType'] == 0:userInfo['touristType'] = 1a += 1elif tourist['ageType'] == 1:userInfo['ageType'] = 2b += 1else:userInfo['ageType'] = 3userInfo['firstname'] = ''userInfo['psptId'] = tourist['cardNum']userInfo['lastname'] = ''userInfo['birthday'] = tourist['birthday']userInfo['tel'] = parameter['data']['contact']['mobile']userInfo['intlCode'] = '0086'userInfo['index'] = cc += 1touristList.append(userInfo)payload_dict['touristList'] = touristListpayload_dict['flightInfo']['vendorId'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['vendorId']payload_dict['flightInfo']['mainAirCom'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['airCodes']payload_dict['flightInfo']['flightNos'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['flightKey']payload_dict['flightInfo']['checkID'] = checkprice['data']['checkID']payload_dict['flightInfo']['queryId'] = queryIdpayload_dict['flightInfo']['cabinCodes'] = parameter["data"]["routing"]["fromSegments"][0]['cabin']payload_dict['flightInfo']["cabinClasses"] = parameter["data"]["routing"]["fromSegments"][0]['cabinGrade']payload_dict['flightInfo']['flightId'] = vebdorId['data']['fareList'][0]['flightId']payload_dict['flightInfo']['adultSeatNum'] = cobin['priceJourneyCabinList'][0]['priceFlightCabinList'][0]['specCabinStatus']payload_dict['flightInfo']['childSeatNum'] = cobin['priceJourneyCabinList'][0]['priceFlightCabinList'][0]['specCabinStatus']payload_dict['flightInfo']['isShareFlight'] = 0priceinfo = payload_dict['priceDetail']priceinfo['adultQuantity'] = apriceinfo['childQuantity'] = bpriceinfo['adultPrice'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['adultPrice']priceinfo['adultBasePrice'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['adultBasePrice']priceinfo['adultTax'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['adultAirportTax']priceinfo['childPrice'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['childPrice']priceinfo['childBasePrice'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['childBasePrice']priceinfo['childTax'] = 0priceinfo['price'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['adultPrice']priceinfo['adultFuel'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['adultFuleTax']priceinfo['childFuel'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['priceList'][0]['childFuleTax']priceinfo['fullPrice'] = 1240armFlight = payload_dict['armFlights'][0]armFlight['flightNo'] = checkprice['data']['vendorList'][0]["jouneyList"][0]['flightKey']armFlight['vendorId'] = checkprice['data']['vendorList'][0]["jouneyList"][0]['vendorId']armFlight['departDate'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['flightOptions'][0]['flightSegs'][0]['departureDate']armFlight['flyTimeStart'] = \checkprice['data']['vendorList'][0]['jouneyList'][0]['flightOptions'][0]['flightSegs'][0]['departureTime']armFlight['flyTimeEnd'] = checkprice['data']['vendorList'][0]['jouneyList'][0]['flightOptions'][0]['flightSegs'][0]['arrivalTime']armFlight['orgCityName'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['dCityName']armFlight['dstCityName'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['aCityName']armFlight['airComIata'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['airCodes']armFlight['airComName'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['flightItems'][0]['airlineCompany']armFlight['orgAirportCode'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['flightItems'][0]['dPortIataCode']armFlight['dstAirportCode'] = vebdorId['data']['fareList'][0]['flightOptions'][0]['flightItems'][0]['aPortIataCode']# payload = json.dumps(payload_dict)# print(json.dumps(payload_dict))headers = {'Connection': "keep-alive",'Pragma': "no-cache",'Cache-Control': "no-cache",'Origin': "",'Upgrade-Insecure-Requests': "1",'Content-Type': "application/x-www-form-urlencoded",'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",'Sec-Fetch-Mode': "nested-navigate",'Sec-Fetch-User': "?1",'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",'Sec-Fetch-Site': "same-site",'Referer': "/domestic/book/?systemId=52&vendorId=1&cabinCodes=L&priceInfoId=&specVendorId=&ruleCode=130&queryId=Y2l0eUtleXM9TktHLUZPQyxkZXBhcnR1cmVEYXRlPTIwMTktMDgtMjEsZGVwYXJ0dXJlRGF0ZXM9MCxwYXNzZW5nZXJRdWFudGl0eT0xIzAjMCMwLHBoeXNpY2FsQ2FiaW49bnVsbA%3D%3D&flightNos=CZ5019",'Accept-Encoding': "gzip, deflate, br",'Accept-Language': "zh-CN,zh;q=0.9",'Cookie': "p_phone_400=4007-999-999; p_phone_level=0; p_global_phone=%2B0086-25-8685-9999; _tacau=MCxkZmQwYWIyNS1mODdmLTk4YzMtYTUxNi0xYjMyNTBjOWViNzYs; _tact=MWU4M2U3MzktMjdkYi1mMjRkLWU4YjMtZWNhYzJjMGEzNzlk; _tacc=1; _ga=GA1.2.1041339263.1565853110; MOBILE_APP_SETTING_STATE-132=CLOSE; fp_ver=4.7.3; BSFIT_EXPIRATION=1567179952515; BSFIT_OkLJUJ=FHNqgzgy71PSvfjfiCGpaO93_rv2uKeg; BSFIT_DEVICEID=HmHHJ0_7ahywv6WTL4O8M5WL43dl3QfVfgVyjIUtbHmz9kv6Oc4LTZ6FufapNHC0ZQXIzWF_cvqbyQ4StHAIxS2xJrqmK_MJ2X9iAXwfaVLggUwvfIc_Z3sBPBW5vuIS-hT81btDiq2h5cAZmzXqrgQ6L2_J7I7H; tuniuuser_id=90646715; rg_entrance=010000%2F003001%2F000013%2F000000; _gid=GA1.2.1722209468.1566177007; PageSwitch=1%2C213612736; MOBILE_APP_SETTING_STATE-126=CLOSE; connect.sid=s%3AA4FCiC9dcCueyGs4PhaR3WDT3wdr1U-g.A8KtYxcA4gSRdEFbMTjPCXju7KYGrlGiurE%2B7Ksq2Vs; tuniu_channel=MTAwLDAsZDdiY2U0NTViYjViMDFhNWExYzk1YTM2ZjZiNDEyY2Q%3D; __xsptplus352=352.3.1566202870.1566202870.1%234%7C%7C%7C%7C%7C%23%23z6C7shy0L5hy3-ZoBsA4WRMHpOgcvi9n%23; tuniu_partner=MTQwMCwwLCwzMTExMWViZjMxNTgyMWUxOTcwZWE0YTAzNzZhMDRjMw%3D%3D; _tacz2=taccsr%3Dbaidu%7Ctacccn%3D%28organic%29%7Ctaccmd%3Dmkt_06002401%7Ctaccct%3Dtuniu%7Ctaccrt%3D%28none%29; __utma=1.1041339263.1565853110.1566367929.1566367929.1; __utmc=1; __utmz=1.1566367929.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); MOBILE_APP_SETTING_OPEN-126=1; tuniu_zeus=MV8xXzFfMV8xXzE6Omh0dHBzOi8vbmoudHVuaXUuY29tLzo6MjAxOS0wOC0yMCAxNDozODo1MQ%3D%3D%2CMV8xXzFfMV8wXzE6Omh0dHA6Ly93d3cudHVuaXUuY29tLz9wPTE0MDAmY21waWQ9bWt0XzA2MDAyNDAxJnV0bV9zb3VyY2U9YmFpZHUmdXRtX21lZGl1bT1icmFuZCZ1dG1fY2FtcGFpZ249YnJhbmQ6OjIwMTktMDgtMjEgMTQ6MTA6NTQ%3D%2CMV8xXzFfMV8wXzE6Omh0dHBzOi8vd3d3LnR1bml1LmNvbS86OjIwMTktMDgtMjEgMTQ6MTI6MjM%3D%2CMV8xXzFfMV8wXzE6Omh0dHBzOi8vd3d3LnR1bml1LmNvbS86OjIwMTktMDgtMjEgMTQ6MTI6MzQ%3D%2CMV8xXzFfMV8wXzE6Omh0dHA6Ly93d3cudHVuaXUuY29tLz9wPTE0MDAmY21waWQ9bWt0XzA2MDAyNDAxJnV0bV9zb3VyY2U9YmFpZHUmdXRtX21lZGl1bT1icmFuZCZ1dG1fY2FtcGFpZ249YnJhbmQ6OjIwMTktMDgtMjEgMTQ6MTI6NDI%3D%2CMV8xXzFfMV8xXzE6Omh0dHBzOi8vaS50dW5pdS5jb20vOjoyMDE5LTA4LTIxIDE2OjQxOjA2%2CMV8xXzFfMV8wXzE6Omh0dHA6Ly93d3cudHVuaXUuY29tLzo6MjAxOS0wOC0yMSAxNjo1MDoxMA%3D%3D%2CMV8xXzFfMV8xXzE6Omh0dHBzOi8vaS50dW5pdS5jb20vOjoyMDE5LTA4LTIxIDE2OjUzOjMx%2CMV8xXzFfMV8xXzE6Omh0dHBzOi8vaS50dW5pdS5jb20vOjoyMDE5LTA4LTIxIDE2OjUzOjM5%2CMV8xXzFfMV8wXzE6Omh0dHA6Ly93d3cudHVuaXUuY29tLzo6MjAxOS0wOC0yMSAxNjo1NDowNw%3D%3D%2CMV8xXzFfMV8xXzE6Omh0dHBzOi8vaS50dW5pdS5jb20vOjoyMDE5LTA4LTIxIDE3OjAwOjM5; OLBSESSID=er5rdkl7ntcanu3bgh7vm25s91; isLogined=true; ssoUser=305aa945ad787f9814ea05ac9ccb3379; tuniuuser_force_logout=1566378140000; tuniuuser_cust_type=MA%3D%3D; tuniuuser=OTA2NDY3MTUsODE3NTYzMzY5OSw4MTc1NjMzNjk5LDAsMTU2NjM3ODE3MSwzYWNkZTBjYWIxNDU4M2YwZDM4NDg0OTg5MGMwYjEzYw%3D%3D; tuniusub=1; tuniuuser_vip=MA%3D%3D; tuniuuser_level=MA%3D%3D; tuniuuser_name=ODE3NTYzMzY5OQ%3D%3D; Hm_lvt_51d49a7cda10d5dd86537755f081cc02=1565853821,1566379656; tuniuuser_ip_citycode=MTYwMg==; tuniuuser_citycode=MTYwMg%3D%3D; _taca=1565853102951.1566376866908.1566436670928.28; _tacb=ZDE1ZjFlZTUtZmM4Ni05NGRjLTZmMjQtOGQ4MmJlMGZiMDA0; _pzfxuvpc=1565853109308%7C3278409822132529745%7C25%7C1566436670969%7C15%7C9549018013103975512%7C1582778554450223618; _pzfxsvpc=1582778554450223618%7C1566436670966%7C1%7Chttps%3A%2F%%2F; Hm_lpvt_51d49a7cda10d5dd86537755f081cc02=1566436722; _gat=1",'Host': "flight-",'Content-Length': "2499",'cache-control': "no-cache"}response = requests.request("POST", url, data=json.dumps(payload_dict), headers=headers)res = response.textcontent = re.search(r'\{.*\}', res).group()# print(content)return json.loads(content)def get_pice(orderID):import requestsurl = "/members/user/order/getOrderList"querystring = {"c": "%7B%22cc%22%3A200%2C%22ct%22%3A10%2C%22p%22%3A14588%2C%22ov%22%3A20%2C%22dt%22%3A0%2C%22v%22%3A%2210.15.1%22%7D","d": "%7B%22productType%22%3A0%2C%22statusKey%22%3A0%2C%22isVirtural%22%3A0%2C%22pageLimit%22%3A8%2C%22sessionId%22%3A%224471b340eddc81379bb012b7f251a223_%22%2C%22sortKey%22%3A0%2C%22pageNum%22%3A1%7D"}headers = {'Cookie': "IDFA=9B86281B-B9D4-4884-AA89-B90F7E2D8C15; IDFV=40555929-3491-437C-92C3-FE12E1ECCA39; TUNIUmuser=4471b340eddc81379bb012b7f251a223_; appVersion=10.15.1; app_imei=795ec662c248948a4f7a2b94e4b9d8e5e6344883; clientType=10; deviceType=0; from_position_url=; from_url=; full_screen_top_height=20; ov=20; sessionId=MzA=; token=OUI4NjI4MUItQjlENC00ODg0LUFBODktQjkwRjdFMkQ4QzE1; tuniu_partner=MTQ1ODgsMCwsMjdiMDIyYTQ0MWJiNzM2NWE0MTc0MmQ4M2I0YjZmNDA=; tuniuuser_citycode=MjAw; tuniuuser_id=90646715; _tacb=Yzk5NTU3YTEtZDE4OS0yNzBhLWMwNmMtMzI5NzA1OWNkM2Nk; _tact=MDllNTQ5ZGYtYTllZi1mMmYyLTdlYmQtNjdiYjM1ZmJhZmMy,IDFA=9B86281B-B9D4-4884-AA89-B90F7E2D8C15; IDFV=40555929-3491-437C-92C3-FE12E1ECCA39; TUNIUmuser=4471b340eddc81379bb012b7f251a223_; appVersion=10.15.1; app_imei=795ec662c248948a4f7a2b94e4b9d8e5e6344883; clientType=10; deviceType=0; from_position_url=; from_url=; full_screen_top_height=20; ov=20; sessionId=MzA=; token=OUI4NjI4MUItQjlENC00ODg0LUFBODktQjkwRjdFMkQ4QzE1; tuniu_partner=MTQ1ODgsMCwsMjdiMDIyYTQ0MWJiNzM2NWE0MTc0MmQ4M2I0YjZmNDA=; tuniuuser_citycode=MjAw; tuniuuser_id=90646715; _tacb=Yzk5NTU3YTEtZDE4OS0yNzBhLWMwNmMtMzI5NzA1OWNkM2Nk; _tact=MDllNTQ5ZGYtYTllZi1mMmYyLTdlYmQtNjdiYjM1ZmJhZmMy; tuniu_partner=MTAxLDAsLDlmZDgyZThjYTZkNGMwMTlmZTUyNzdlYjJmNTcxYzQ1; tuniuuser_citycode=MjAw; p_phone_400=4007-999-999; p_phone_level=0; p_global_phone=%2B0086-25-8685-9999; OLBSESSID=s0lgipeeebnq81ecbqd67p3is5",'sessionid': "4471b340eddc81379bb012b7f251a223_",'Accept': "*/*",'Content-Type': "application/json; charset=utf-8",'Accept-Encoding': "br, gzip, deflate",'Host': "",'User-Agent': "TuNiuApp/10.15.1 (iOS)",'Connection': "keep-alive",'sid': "B42BCB38-EFBD-4EA0-B69D-5B9E4A598794",'Accept-Language': "zh-Hans-CN;q=1",'Cache-Control': "no-cache",'Postman-Token': "8826f39c-1ff3-4e25-8ea9-1f51de5416dc,7196b7a0-37d7-4bf1-9250-46a9f8d70795",'cache-control': "no-cache"}response = requests.request("GET", url, headers=headers, params=querystring).json()try:order_list = response['data']['orderList']for order in order_list:if orderID == order['orderId']:return order['price']except:time.sleep(3)response = requests.request("GET", url, headers=headers, params=querystring).json()order_list = response['data']['orderList']for order in order_list:if orderID == order['orderId']:return order['price']# print(response.text)def workOn(parameter):# parameter = '{"account": 1,"dep_code":"TSN","arr_code":"YIH","fromDate":"-09-01", "data": {"routing": {"retSegments": [], "fromSegments": [{"depTime": "-08-08 22:40", "cabinGrade": "Y", "cabin": "M", "depAirport": "INC", "publishPrice": 1220, "flightNumber": "HU7792", "carrier": "GJ", "codeShare": false, "aircraftCode": "320", "arrAirport": "URC", "construcFee": 50, "fuleFee": 0, "arrTime": "-08-09 01:45"}]}, "passengers": [{"birthday": "1959-10-02", "cardNum": "642223195910020326", "gender": "F", "name": "\u5218\u7389\u6885", "cardType": "NI", "ageType": 0}], "contact": {"name": "\u6b27\u9633\u5a1c\u5a1c", "mobile": "18513135661"}, "orderStatus": 1, "sourceOrderNo": "1908071000291159"}, "createTime": "1565143229757", "cid": "zhenlv"}'queryId = get_flight(parameter)# print(queryId)vebdorId = get_vendorid(queryId, parameter)# print(vebdorId)cobin = get_price(parameter, vebdorId)# print(cobin)if cobin["aduDivideBaby"] != "未查询到相应座位":checkprice = check_price(parameter, queryId, vebdorId, cobin)orderID = save_order(parameter=parameter, queryId=queryId, vebdorId=vebdorId, checkprice=checkprice,cobin=cobin)# print(json.dumps(orderID))orderID = orderID["data"]["orderId"]pice = get_pice(orderID)orderID_dict = {"status": 0, "msg": "success", "orderID": orderID, "totalPrice": pice}return json.dumps(orderID_dict)else:return {"status": 3, "msg": "订票失败", "orderID": ""}if __name__ == '__main__':parameter = '{"account": 1,"dep_code":"TSN","arr_code":"YIH","fromDate":"-10-22", "data": {"routing": {"retSegments": [], "fromSegments": [{"depTime": "-08-08 22:40", "cabinGrade": "Y", "cabin": "N", "depAirport": "INC", "publishPrice": 1220, "flightNumber": "HU7792", "carrier": "GJ", "codeShare": false, "aircraftCode": "320", "arrAirport": "URC", "construcFee": 50, "fuleFee": 0, "arrTime": "-08-09 01:45"}]}, "passengers": [{"birthday": "1959-10-02", "cardNum": "642223195910020326", "gender": "F", "name": "\u5218\u7389", "cardType": "NI", "ageType": 0},{"birthday": "1989-04-22", "cardNum": "43198904223712", "gender": "F", "name": "\u6b27\u9633\u5a1c", "cardType": "NI", "ageType": 0}], "contact": {"name": "\u6b27\u5a1c\u5a1c", "mobile": "18511111111"}, "orderStatus": 1, "sourceOrderNo": "1908071000291159"}, "createTime": "1565143229757", "cid": "zhenlv"}'# print(workOn(parameter))# while True:#print(get_flight(parameter))print(workOn(parameter))
700字范文,内容丰富有趣,生活中的好帮手!