Ver código fonte

Python生单1.0代码

zhangqf 6 anos atrás
commit
b2bdb12552

Diferenças do arquivo suprimidas por serem muito extensas
+ 320 - 0
src/entity/OrderInfo.py


+ 0 - 0
src/entity/__init__.py


BIN
src/entity/__pycache__/OrderInfo.cpython-36.pyc


BIN
src/entity/__pycache__/__init__.cpython-36.pyc


Diferenças do arquivo suprimidas por serem muito extensas
+ 360 - 0
src/order/AkOrderTest.py


Diferenças do arquivo suprimidas por serem muito extensas
+ 140 - 0
src/order/Test.py


+ 0 - 0
src/order/__init__.py


+ 85 - 0
src/query/AkBigQuery.py

@@ -0,0 +1,85 @@
+#-*- coding:utf-8 -*-
+import json
+import requests
+import datetime
+
+class AkBigQuery:
+    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.29.146/bigsearch/airasia/big/app/testsearch'
+        headers = {'Content-Type': 'application/json'}
+        fromJson = {}
+        retJson = {}
+        session = requests.session()
+        res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
+        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'] = ''
+                        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'
+    akbig = AkBigQuery(queryInputJson,2,flightList,retFlights)
+    fromQueryJson,retQuerJson = akbig.StartQuery()
+    print(fromQueryJson)
+    print(retQuerJson)
+        
+    end = datetime.datetime.now()
+    k = end - begin
+    print(k.total_seconds())
+        

+ 84 - 0
src/query/AkWebQuery.py

@@ -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())

+ 0 - 0
src/query/__init__.py


+ 10 - 0
src/thread/Atest.py

@@ -0,0 +1,10 @@
+#-*- coding:utf-8 -*-
+import time
+class Atest:
+    num = '';
+    def __init__(self,num):
+        print('Web启动获取:'+num)
+        self.num = num
+    def statQuery(self):
+        time.sleep(3)
+        print(self.num+'Web执行完毕!')

+ 10 - 0
src/thread/Btest.py

@@ -0,0 +1,10 @@
+#-*- coding:utf-8 -*-
+import time
+class Btest:
+    num = '';
+    def __init__(self,num):
+        print('Big启动获取:'+num)
+        self.num = num
+    def statQuery(self):
+        time.sleep(3)
+        print(self.num+'Bigִ执行完毕!')

+ 25 - 0
src/thread/ThreadTest.py

@@ -0,0 +1,25 @@
+#-*- coding:utf-8 -*-
+import threading
+import time
+
+def run():
+    time.sleep(2)
+    print('当前线程的名字是: ', threading.current_thread().name)
+    time.sleep(2)
+
+
+if __name__ == '__main__':
+
+    start_time = time.time()
+
+    print('这是主线程:', threading.current_thread().name)
+    thread_list = []
+    for i in range(5):
+        t = threading.Thread(target=run)
+        thread_list.append(t)
+
+    for t in thread_list:
+        t.start()
+
+    print('主线程结束!' , threading.current_thread().name)
+    print('一共用时:', time.time()-start_time)

+ 33 - 0
src/thread/ThreadTest1.py

@@ -0,0 +1,33 @@
+#-*- coding:utf-8 -*-
+import threading
+from thread.Atest import Atest
+from thread.Btest import Btest
+
+class Manage:
+    def __init__(self):
+        print('主线程初始化!')
+    def AtestStart(self):
+        print('准备启动Web查询', threading.current_thread().name)
+        thread_list = []
+        for i in range(5):
+            a = Atest('Web'+str(i)) 
+            t = threading.Thread(target=a.statQuery())
+            thread_list.append(t)
+        for t in thread_list:
+            t.start()
+    def BtestStart(self):
+        print('准备启动Web查询', threading.current_thread().name)
+        thread_list = []
+        for i in range(5):
+            b = Btest('Web'+str(i)) 
+            t = threading.Thread(target=b.statQuery())
+            thread_list.append(t)
+        for t in thread_list:
+            t.start()
+            
+if __name__ == '__main__':
+    m = Manage()
+    print('启动五个Web爬虫线程')
+    m.AtestStart()
+    print('启动五个Big爬虫线程')
+    m.BtestStart()

+ 0 - 0
src/thread/__init__.py


+ 67 - 0
src/utils/CallbackOrderUtils.py

@@ -0,0 +1,67 @@
+#-*- coding:utf-8 -*-
+import requests
+import json
+from entity.OrderInfo import Currency
+
+class CallbackOrderUtils():
+    
+    callbackurl = "http://203.130.42.247/mgr/"
+    #callbackurl = "http://192.168.1.5:11009/"
+    
+    def __init__(self):
+        '''
+        Constructor
+        '''
+    #回调占座结果
+    def BallbackOrder(self,orderNo,orderStatus,orderPnr,accountType,userName):
+        url = self.callbackurl+"orOrdertb/orderCallBack"
+        fromParam = {}
+        fromParam['orderNo'] = orderNo
+        fromParam['orderStatus'] = orderStatus
+        fromParam['orderPnr'] = orderPnr
+        fromParam['accountType'] = accountType
+        fromParam['userName'] = userName
+        session = requests.session()
+        res = session.post(url,data=fromParam)
+        print(res.text)
+    #回调价格
+    def BallbackPrice(self,orderNo,webPrice,agentPrice,bigPrice):
+        url = self.callbackurl+"orOrdertb/ballbackPrice"
+        print(url)
+        fromParam = {}
+        fromParam['orderNo'] = orderNo
+        fromParam['webPrice'] = webPrice
+        fromParam['agentPrice'] = agentPrice
+        fromParam['bigPrice'] = bigPrice
+        session = requests.session()
+        res = session.post(url,data=fromParam)
+        print(res.text)
+    #通过机场三字码查询币种与汇率
+    def cityToCurrency(self,stationCode):
+        url = self.callbackurl+"scCitycurrency/cityToCurrency"
+        print(url)
+        fromParam = {}
+        fromParam['stationCode'] = stationCode
+        session = requests.session()
+        res = session.post(url,data=fromParam)
+        json_str = json.loads(res.text)
+        if 200 == json_str['status']:
+            json_str = json_str['attachment']
+            currency = Currency()
+            currency.stationCode = json_str['stationCode']                  #机场三字码
+            currency.currencyCode = json_str['currencyCode']                #币种
+            currency.exchangeCode = json_str['exchangeCode']                #转化币种 一般为CNY
+            currency.countryCode = json_str['countryCode']                  #城市编码
+            currency.UnionPayOriginRate = json_str['UnionPayOriginRate']    #银联原始汇率
+            currency.UnionPayFinalRate = json_str['UnionPayFinalRate']      #银联调整后汇率
+            currency.AkOriginRate = json_str['AkOriginRate']                #亚航原始汇率
+            currency.AkFinalRate = json_str['AkFinalRate']                  #亚航调整后汇率
+            return currency
+        return
+if __name__ == '__main__':
+    cout = CallbackOrderUtils()
+    #cout.BallbackOrder('2018030915450779734174620', '1', 'YUNIHJ', '代理人占座', 'CNTRIPTOPK_ADMIN')
+    retText = cout.cityToCurrency('CAN')
+    print(retText)
+    
+    

+ 0 - 0
src/utils/__init__.py


BIN
src/utils/__pycache__/CallbackOrderUtils.cpython-36.pyc


BIN
src/utils/__pycache__/__init__.cpython-36.pyc


+ 24 - 0
src/webserver/IndexHandler.py

@@ -0,0 +1,24 @@
+#-*- coding:utf-8 -*-
+import tornado.web
+import tornado.ioloop
+import json
+
+#定义处理类型
+class IndexHandler(tornado.web.RequestHandler):
+    #添加一个处理get请求方式的方法
+    def get(self):
+        #向响应中,添加数据
+        self.write('好看的皮囊千篇一律,有趣的灵魂万里挑一。')
+
+    def post(self):
+        param = self.request.body.decode('utf-8')
+        prarm = json.loads(param)
+        print(param)
+        self.write('Ok')
+if __name__ == '__main__':
+    #创建一个应用对象
+    app = tornado.web.Application([(r'/',IndexHandler)])
+    #绑定一个监听端口
+    app.listen(8888)
+    #启动web程序,开始监听端口的连接
+    tornado.ioloop.IOLoop.current().start()

+ 0 - 0
src/webserver/__init__.py