zhangqf 6 роки тому
батько
коміт
846e3a7823
4 змінених файлів з 166 додано та 98 видалено
  1. 132 77
      src/order/OrderServer.py
  2. 3 3
      src/query/AkBigQuery.py
  3. 1 1
      src/query/AkWebQuery.py
  4. 30 17
      src/test/PessHtmlTest.py

+ 132 - 77
src/order/OrderServer.py

@@ -49,13 +49,17 @@ class OrderServer():
         self.passengers_chd = [] #儿童乘客
         self.passengers_infant = []#婴儿乘客
         #行李 PBAB:20Kg PBAC:25Kg PBAD:30Kg PBAF:40Kg
-        self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'} 
+        self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'}
         
         self._web_value_lock = threading.Lock() #实例化 Web查询
         self._big_value_lock = threading.Lock() #实例化 Big查询
         
         self.sign = False  #是否刷单标记
         self.passengerIds = [] #乘机人ID  List
+        
+        self.luggage = '';#行李编码
+        self.ismeals = False;#是否占套餐
+        self.cabin = 'EC';#占舱类型
     #获取订单信息
     def LoadPrarm(self):
         self.salt = self.json_str['cid']+'|'
@@ -67,6 +71,7 @@ class OrderServer():
         self.oinfo.toCity =self.json_str['toCity']       #到达三字码
         if self.oinfo.tripType == 2:
             self.oinfo.retDate =self.json_str['retDate']     #返程日期 2018-04-29
+            print('反程日期:'+self.json_str['retDate'])
         self.oinfo.adultNum =self.json_str['adultNum']   #成人乘客数
         self.oinfo.childNum =self.json_str['childNum']   #儿童乘客数
         
@@ -122,7 +127,16 @@ class OrderServer():
                 seg.cabin = 'EC'
             if 'EC' != seg.cabin:
                 self.isContinue = False
-                return
+            if 'EC' == seg.cabin or 'EP' == seg.cabin:
+                self.luggage = 'PBNO'
+            elif 'VF' == seg.cabin or 'HF' == seg.cabin:
+                self.luggage = 'PBAB'
+                self.ismeals = True
+            elif 'PM' == seg.cabin:
+                self.luggage = 'PBAF'
+                self.ismeals = True
+            self.cabin = seg.cabin
+            
             seg.depAirport = kfsa['depAirport']    #出发机场IATA三字码   KUL
             seg.arrAirport = kfsa['arrAirport']    #到达机场IATA三字码   DPS
             seg.arrTime = kfsa['arrTime']       #起飞时间20180428053
@@ -205,6 +219,7 @@ class OrderServer():
 #         self._web_value_lock.release() #web结果锁 开始
     #发起Big查询
     def BigQuery(self):
+        self.queryInputJson['airSource'] = 'AK_BIG_APP';
         akbigQuer = AkBigQuery(self.queryInputJson,self.oinfo.tripType,self.oinfo.fromFlight,self.oinfo.retFlight,self.oinfo.fxRate)
         akQueryBigFrom,akQueryBigRet,isOk = akbigQuer.StartQuery()
 #         self._big_value_lock.acquire()#web结果锁 开始
@@ -227,14 +242,14 @@ class OrderServer():
     def AagenLogin(self):
         
         #添加代理IP
-        cl = call()
-        proxyurl = cl.getProxyIP()
-        proxy_handler = {
-            'http': 'http://'+proxyurl,
-            'https': 'https://'+proxyurl,
-        }
-        self.session.proxies = proxy_handler
-        logging.info(self.salt+'IP:'+proxyurl)
+#         cl = call()
+#         proxyurl = cl.getProxyIP()
+#         proxy_handler = {
+#             'http': 'http://'+proxyurl,
+#             'https': 'https://'+proxyurl,
+#         }
+#         self.session.proxies = proxy_handler
+#         logging.info(self.salt+'IP:'+proxyurl)
         res = self.session.get("https://www.airasia.com/my/en/login/travel-agent.page")
         page = etree.HTML(res.text)
         self.logindata['__VIEWSTATE'] = page.xpath("//input[@name='__VIEWSTATE']/@value")[0]
@@ -453,35 +468,44 @@ class OrderServer():
         #先回调价格,其次比价EC EP   
         cl = call()
         cl.BallbackPrice(self.oinfo.cid, str(self.oinfo.webFromJson),str(self.oinfo.webRetJson), str(self.oinfo.agentFromJson),str(self.oinfo.agentRetJson),str(self.oinfo.bigFromJson),str(self.oinfo.bigRetJson),self.sign)
-        
+        #EC.特惠 EP.低航费 VF.超值套餐 HF.常飞客 PM.豪华平躺
         agfPrice = 0.0 #代理人价格
         agrPrice = 0.0 #代理人价格
         agfromVal = '' #代理人去程提交字符串
         agretVal = '' #代理人返程提交字符串
         agfromPrice = self.oinfo.agentFromJson
         agretPrice = self.oinfo.agentRetJson
-        if 'EC' in agfromPrice.keys():
-            agfPrice = agfromPrice['EC']['priceTotal']
-            agfromVal = agfromPrice['EC']['radioValue']
-        if 'EP' in agfromPrice.keys():
-            if agfPrice != 0.0 and agfPrice > agfromPrice['EP']['priceTotal']:
-                agfPrice = agfromPrice['EP']['priceTotal']
-                agfromVal = agfromPrice['EP']['radioValue']
-            if agfPrice == 0.0:
-                agfPrice = agfromPrice['EP']['priceTotal']
-                agfromVal = agfromPrice['EP']['radioValue']
-        if agretPrice != None:
-            if 'EC' in agretPrice.keys():
-                agrPrice = agretPrice['EC']['priceTotal']
-                agretVal = agretPrice['EC']['radioValue']
-            if 'EP' in agretPrice.keys():
-                if agrPrice != 0.0 and agrPrice > agretPrice['EP']['priceTotal']:
-                    agrPrice = agretPrice['EP']['priceTotal']
-                    agretVal = agretPrice['EP']['radioValue']
-                if agrPrice == 0.0:
-                    agrPrice = agretPrice['EP']['priceTotal']
-                    agretVal = agretPrice['EP']['radioValue']
-                    
+        if 'EC' in  self.cabin:
+            if 'EC' in agfromPrice.keys():
+                agfPrice = agfromPrice['EC']['priceTotal']
+                agfromVal = agfromPrice['EC']['radioValue']
+            if 'EP' in agfromPrice.keys():
+                if agfPrice != 0.0 and agfPrice > agfromPrice['EP']['priceTotal']:
+                    agfPrice = agfromPrice['EP']['priceTotal']
+                    agfromVal = agfromPrice['EP']['radioValue']
+                if agfPrice == 0.0:
+                    agfPrice = agfromPrice['EP']['priceTotal']
+                    agfromVal = agfromPrice['EP']['radioValue']
+            if agretPrice != None:
+                if 'EC' in agretPrice.keys():
+                    agrPrice = agretPrice['EC']['priceTotal']
+                    agretVal = agretPrice['EC']['radioValue']
+                if 'EP' in agretPrice.keys():
+                    if agrPrice != 0.0 and agrPrice > agretPrice['EP']['priceTotal']:
+                        agrPrice = agretPrice['EP']['priceTotal']
+                        agretVal = agretPrice['EP']['radioValue']
+                    if agrPrice == 0.0:
+                        agrPrice = agretPrice['EP']['priceTotal']
+                        agretVal = agretPrice['EP']['radioValue']
+        else:
+            if self.cabin in agfromPrice.keys():
+                agfPrice = agfromPrice[self.cabin]['priceTotal']
+                agfromVal = agfromPrice[self.cabin]['radioValue']
+            if agretPrice != None:
+                if self.cabin in agretPrice.keys():
+                    agrPrice = agretPrice[self.cabin]['priceTotal']
+                    agretVal = agretPrice[self.cabin]['radioValue']
+                  
         logging.info(self.salt+'代理人去程:'+str(agfPrice)+'   __'+agfromVal)
         logging.info(self.salt+'代理人回程:'+str(agrPrice)+'   __'+agretVal)
         
@@ -491,48 +515,48 @@ class OrderServer():
         webretVal = '' #Web官网返程提交字符串
         webfromPrice = self.oinfo.webFromJson
         webretPrice = self.oinfo.webRetJson
-        if 'EC' in webfromPrice.keys():
-            webfPrice = webfromPrice['EC']['priceTotal']
-            webfromVal = webfromPrice['EC']['radioValue']
+        if self.cabin in webfromPrice.keys():
+            webfPrice = webfromPrice[self.cabin]['priceTotal']
+            webfromVal = webfromPrice[self.cabin]['radioValue']
         if webretPrice != None:
-            if 'EC' in webretPrice.keys():
-                webrPrice = webretPrice['EC']['priceTotal']
-                webretVal = webretPrice['EC']['radioValue']
+            if self.cabin in webretPrice.keys():
+                webrPrice = webretPrice[self.cabin]['priceTotal']
+                webretVal = webretPrice[self.cabin]['radioValue']
                 
         logging.info(self.salt+'Web官网去程:'+str(webfPrice) +'  __'+webfromVal)
         logging.info(self.salt+'Web官网回程:'+str(webrPrice) +'  __'+webretVal)
         
         
-        bigfPrice = 0.0 #Big积分价格
-        bigrPrice = 0.0 #Big积分价格
-        bigfromPrice = self.oinfo.bigFromJson
-        bigretPrice = self.oinfo.bigRetJson
-        if 'EC' in bigfromPrice.keys():
-            bigfPrice = bigfromPrice['EC']['priceTotal']
-        if bigretPrice != None:
-            if 'EC' in bigretPrice.keys():
-                bigrPrice = bigretPrice['EC']['priceTotal']
-        
-        logging.info(self.salt+'Big积分去程价:'+str(bigfPrice))
-        logging.info(self.salt+'Big积分回程价:'+str(bigrPrice))
-        logging.info(self.salt+'Big积分加价55,然后再比价!')
-        if bigfPrice != 0.0:        
-            #一决雌雄  使用那种方式生单  AGENT_ORDER WEB_ORDER BIG_ORDER
-            bigp = bigfPrice + bigrPrice+55
-            webp = webfPrice + webrPrice
-            agp  = agfPrice + agrPrice
-            if webp != 0.0:
-                if bigp < webp and bigp < webp:
-                    #Big价格优势
-                    self.oinfo.modeOrder = 'BIG_ORDER'
-                    logging.info(self.salt+'-----Big价格优势')
-                    return
-            else:
-                if bigp < agp:
-                    #Big价格优势
-                    self.oinfo.modeOrder = 'BIG_ORDER'
-                    logging.info(self.salt+'-----Big价格优势')
-                    return
+#         bigfPrice = 0.0 #Big积分价格
+#         bigrPrice = 0.0 #Big积分价格
+#         bigfromPrice = self.oinfo.bigFromJson
+#         bigretPrice = self.oinfo.bigRetJson
+#         if 'EC' in bigfromPrice.keys():
+#             bigfPrice = bigfromPrice['EC']['priceTotal']
+#         if bigretPrice != None:
+#             if 'EC' in bigretPrice.keys():
+#                 bigrPrice = bigretPrice['EC']['priceTotal']
+#         
+#         logging.info(self.salt+'Big积分去程价:'+str(bigfPrice))
+#         logging.info(self.salt+'Big积分回程价:'+str(bigrPrice))
+#         logging.info(self.salt+'Big积分加价55,然后再比价!')
+#         if bigfPrice != 0.0:        
+#             #一决雌雄  使用那种方式生单  AGENT_ORDER WEB_ORDER BIG_ORDER
+#             bigp = bigfPrice + bigrPrice+55
+#             webp = webfPrice + webrPrice
+#             agp  = agfPrice + agrPrice
+#             if webp != 0.0:
+#                 if bigp < webp and bigp < webp:
+#                     #Big价格优势
+#                     self.oinfo.modeOrder = 'BIG_ORDER'
+#                     logging.info(self.salt+'-----Big价格优势')
+#                     return
+#             else:
+#                 if bigp < agp:
+#                     #Big价格优势
+#                     self.oinfo.modeOrder = 'BIG_ORDER'
+#                     logging.info(self.salt+'-----Big价格优势')
+#                     return
         
         self.oinfo.modeOrder = 'AGENT_ORDER'
         #接下来是官网与代理的对决
@@ -685,21 +709,50 @@ class OrderServer():
             'CONTROLGROUP_OUTERTRAVELER$CONTROLGROUPTRAVELER$ButtonSubmit':'Continue',
             '__VIEWSTATEGENERATOR':'05F9A2B0'
         }
-        #餐食选择
-        for row in page.xpath("//div[starts-with(@class,'ucmealpanel-item-selection-form')]/input/@name"):
-            passengerData[row] = '0'
         #舒适套件
         for row in page.xpath("//div[starts-with(@class,'uccomfortkitpanel-item-selection-form')]/input/@name"):
             passengerData[row] = '0'
             
+        #餐食选择
+        passListarts = []
+        for row in page.xpath("//div[starts-with(@class,'ucmealpanel-item-selection-form')]/input/@name"):
+            if '_group_AAXmealCat' in row:
+                AAXmealCa = row[105:107]+row[136:158]
+                if AAXmealCa not in passListarts:
+                    passListarts.append(AAXmealCa)
+                    passengerData[row] = '1'
+                else:
+                    passengerData[row] = '0'
+                    
         #行李 PBAB:20Kg PBAC:25Kg PBAD:30Kg PBAF:40Kg
         #self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'}
         #行李选择
-        for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
-            if '_previousSsr_' in row:
-                passengerData[row] = 'BWQZ'
-            else:
-                passengerData[row] = ''
+        if self.luggage == 'PBNO':
+            for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
+                if '_previousSsr_' in row:
+                    passengerData[row] = 'BWQZ'
+                else:
+                    passengerData[row] = ''
+        #40Kg            
+        if self.luggage == 'PBAB':
+            for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
+                if 'previousSsr' in row:
+                    passengerData[row] = 'BWMX'
+                else:
+                    vl = row[80:]
+                    vl = vl.replace("journey_1", "ssrCode_PBAB_ssrNum_1");
+                    vl = vl.replace("journey_2", "ssrCode_PBAB_ssrNum_1");
+                    passengerData[row] = vl
+        #40Kg
+        if self.luggage == 'PBAF':
+            for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
+                if 'previousSsr' in row:
+                    passengerData[row] = 'BWMX'
+                else:
+                    vl = row[80:]
+                    vl = vl.replace("journey_1", "ssrCode_PBAF_ssrNum_1");
+                    vl = vl.replace("journey_2", "ssrCode_PBAF_ssrNum_1");
+                    passengerData[row] = vl
             
         self.passengers_adt.extend(self.passengers_chd)
         #成人与儿童
@@ -827,6 +880,8 @@ class OrderServer():
             'HiddenFieldPageBookingData':page.xpath('//input[@id="HiddenFieldPageBookingDataId"]/@value')[0],
             '__VIEWSTATEGENERATOR':'05F9A2B0'
             }
+        logging.info(self.salt+json.dumps(PaymentData))
+        logging.info(self.salt+str(self.session.headers))
         res = self.session.post('https://booking2.airasia.com/Payment.aspx', data=PaymentData, verify=False,timeout = 60)
         logging.info(self.salt+'支付选择提交成,进入下一步!')
         logging.info(self.salt+str(res.status_code))

+ 3 - 3
src/query/AkBigQuery.py

@@ -18,7 +18,7 @@ class AkBigQuery:
         #开始执行时间
         salt = ''.join(random.sample(string.ascii_letters + string.digits, 16))+'|AKBIG'
         start = time.clock()
-        queryUrl = 'http://128.14.29.146/bigsearch/airasia/big/app/testsearch'
+        queryUrl = 'http://128.14.29.226/spider/testsearch'
         headers = {'Content-Type': 'application/json'}
         fromJson = {}
         retJson = {}
@@ -32,7 +32,7 @@ class AkBigQuery:
         logging.info(salt+"|queryInputJson:"+str(self.queryInputJson))
         res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
         #logging.info(salt+"|retJson:"+res.text)
-        #print(res.text)
+        print(res.text)
         json_str = json.loads(res.text)
         if 200 == json_str['status']:
             fromSegments = json_str['attachment']['fromSegments']
@@ -119,7 +119,7 @@ if __name__ == '__main__':
 #     print(aaa)
     
     begin = datetime.datetime.now()    
-    queryInputJson = {"adultNum":1,"childNum":0,"formCity":"KUL","fromDate":"2018-05-13","id":0,"retDate":"","toCity":"CKG","tripType":"1","uuid":"AKBing","currency":"MYR"}
+    queryInputJson = {"airSource":"AK_BIG_APP","adultNum":1,"childNum":0,"formCity":"KUL","fromDate":"2018-05-13","id":0,"retDate":"","toCity":"CKG","tripType":"1","uuid":"AKBing","currency":"MYR"}
     flightList = 'D7808'
     retFlights = 'AK303'
     akbig = AkBigQuery(queryInputJson,1,flightList,retFlights,1)

+ 1 - 1
src/query/AkWebQuery.py

@@ -18,7 +18,7 @@ class AkWebQuery:
     def StartQuery(self):
         start = time.clock()
         salt = ''.join(random.sample(string.ascii_letters + string.digits, 16))+'|AKWEB'
-        queryUrl = 'http://128.14.29.146/bigsearch/ariasiaweb/newsearch'
+        queryUrl = 'http://128.14.29.226/spider/ariasiaweb/newsearch'
         headers = {'Content-Type': 'application/json'}
         fromJson = {}
         retJson = {}

+ 30 - 17
src/test/PessHtmlTest.py

@@ -3,32 +3,45 @@
 from pyquery import PyQuery as pq
 from lxml import etree
 
-f = open('E://ak/testSelect.html',encoding='utf-8')
+f = open('E://ak/testSelectA.html',encoding='utf-8')
 queryHtml = f.read()
 b = pq(queryHtml) 
 page = etree.HTML(queryHtml)
 
-print('--------------------选择行李')
-for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
-    print(row)
+# print('--------------------选择行李')
+# for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
+#     if 'previousSsr' in row:
+#         print(row+'=BWQZ')
+#     else:
+#         vl = row[80:]
+#         vl = vl.replace("journey_1", "ssrCode_PBAB_ssrNum_1");
+#         vl = vl.replace("journey_2", "ssrCode_PBAB_ssrNum_1");
+#         print(row+'='+vl)
 
 print('--------------------餐食选择')
 #餐食选择
+#map(lambda k:k[],)
+li = []
 for row in page.xpath("//div[starts-with(@class,'ucmealpanel-item-selection-form')]/input/@name"):
-    print(row)
-
+    if '_group_AAXmealCat' in row:
+        if row[105:107]+row[136:158] not in li:
+            print(row[105:107]+row[136:158]+'----------------1')
+            li.append(row[105:107]+row[136:158])
+        else:
+            print(row[105:107]+row[136:158]+'----------------0')
+ 
 print('--------------------选择舒适套件')
-
-#选择舒适套件
-for row in page.xpath("//div[starts-with(@class,'uccomfortkitpanel-item-selection-form')]/input/@name"):
-    print(row)
-
-
-
-HiFlyerFare = page.xpath("//input[@name='HiFlyerFare']/@value")
-print('HiFlyerFare:'+str(HiFlyerFare))
-HiddenFieldPageBookingData = page.xpath("//input[@name='HiddenFieldPageBookingData']/@value")
-print('HiddenFieldPageBookingData:'+str(HiddenFieldPageBookingData))
+# 
+# #选择舒适套件
+# for row in page.xpath("//div[starts-with(@class,'uccomfortkitpanel-item-selection-form')]/input/@name"):
+#     print(row)
+# 
+# 
+# 
+# HiFlyerFare = page.xpath("//input[@name='HiFlyerFare']/@value")
+# print('HiFlyerFare:'+str(HiFlyerFare))
+# HiddenFieldPageBookingData = page.xpath("//input[@name='HiddenFieldPageBookingData']/@value")
+# print('HiddenFieldPageBookingData:'+str(HiddenFieldPageBookingData))
 
 print('----------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------')