|
@@ -0,0 +1,84 @@
|
|
|
+#-*- coding:utf-8 -*-
|
|
|
+import json
|
|
|
+import requests
|
|
|
+import datetime
|
|
|
+
|
|
|
+class AkWebQuery:
|
|
|
+ def __init__(self,queryInputJson,tripType,flightList,retFlights):
|
|
|
+ self.flightList = flightList
|
|
|
+ self.retFlights = retFlights
|
|
|
+ self.tripType = tripType
|
|
|
+ self.queryInputJson = queryInputJson
|
|
|
+ def StartQuery(self):
|
|
|
+ queryUrl = 'http://128.14.30.106/spider/ariasiaweb/testsearch'
|
|
|
+ headers = {'Content-Type': 'application/json'}
|
|
|
+ fromJson = {}
|
|
|
+ retJson = {}
|
|
|
+ session = requests.session()
|
|
|
+ res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
|
|
|
+ #print(res.status_code)
|
|
|
+ print(res.text)
|
|
|
+ json_str = json.loads(res.text)
|
|
|
+ if 200 == json_str['status']:
|
|
|
+ fromSegments = json_str['attachment']['fromSegments']
|
|
|
+ for k in fromSegments:
|
|
|
+ routeInfoEntities = k['routeInfoEntities']
|
|
|
+ flightNumber = ''
|
|
|
+ goOn = True
|
|
|
+ for i in routeInfoEntities:
|
|
|
+ flightNumber += ','+i['flightNumber']
|
|
|
+ if i['flightNumber'] not in self.flightList:
|
|
|
+ goOn = False
|
|
|
+ break
|
|
|
+ if goOn:
|
|
|
+ airlinePriceInfos = routeInfoEntities = k['airlinePriceInfos']
|
|
|
+ for i in airlinePriceInfos:
|
|
|
+ typsJson = {}
|
|
|
+ typsJson['currency'] = k['currency']
|
|
|
+ typsJson['cabin'] = i['cabin']
|
|
|
+ typsJson['cabinName'] = i['cabinName']
|
|
|
+ typsJson['adultPrice'] = i['adultPrice']
|
|
|
+ typsJson['adultTax'] = i['adultTax']
|
|
|
+ typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
|
|
|
+ typsJson['radioValue'] = '0~O~~O00H00~AAB1~~2024~X|QZ~ 555~ ~~KUL~04/29/2018 21:50~DPS~04/30/2018 00:55~@04/29/2018 13:50:00'
|
|
|
+ fromJson[i['cabin']] = typsJson
|
|
|
+ break
|
|
|
+ if 2 == self.tripType:
|
|
|
+ retSegments = json_str['attachment']['retSegments']
|
|
|
+ for k in retSegments:
|
|
|
+ routeInfoEntities = k['routeInfoEntities']
|
|
|
+ flightNumber = ''
|
|
|
+ goOn = True
|
|
|
+ for i in routeInfoEntities:
|
|
|
+ flightNumber += ','+i['flightNumber']
|
|
|
+ if i['flightNumber'] not in self.retFlights:
|
|
|
+ goOn = False
|
|
|
+ break
|
|
|
+ if goOn:
|
|
|
+ airlinePriceInfos = routeInfoEntities = k['airlinePriceInfos']
|
|
|
+ for i in airlinePriceInfos:
|
|
|
+ typsJson = {}
|
|
|
+ typsJson['currency'] = k['currency']
|
|
|
+ typsJson['cabin'] = i['cabin']
|
|
|
+ typsJson['cabinName'] = i['cabinName']
|
|
|
+ typsJson['adultPrice'] = i['adultPrice']
|
|
|
+ typsJson['adultTax'] = i['adultTax']
|
|
|
+ typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
|
|
|
+ typsJson['radioValue'] = '0~O~~O00H00~AAB1~~2024~X|QZ~ 555~ ~~KUL~04/29/2018 21:50~DPS~04/30/2018 00:55~@04/29/2018 13:50:00'
|
|
|
+ retJson[i['cabin']] = typsJson
|
|
|
+ break
|
|
|
+ return (fromJson,retJson)
|
|
|
+if __name__ == '__main__':
|
|
|
+ begin = datetime.datetime.now()
|
|
|
+
|
|
|
+ queryInputJson = {"adultNum":1,"childNum":0,"formCity":"KUL","fromDate":"2018-04-29","id":0,"retDate":"2018-05-29","toCity":"DPS","tripType":"2","uuid":"AKBing","currency":"CNY"}
|
|
|
+ flightList = 'QZ555'
|
|
|
+ retFlights = 'AK377'
|
|
|
+ akweb = AkWebQuery(queryInputJson,2,flightList,retFlights)
|
|
|
+ fromQueryJson,retQuerJson = akweb.StartQuery()
|
|
|
+ print(fromQueryJson)
|
|
|
+ print(retQuerJson)
|
|
|
+
|
|
|
+ end = datetime.datetime.now()
|
|
|
+ k = end - begin
|
|
|
+ print(k.total_seconds())
|