Example #1
0
    def get_data(self):
        #print(self.data)
        r = requests.post(url=self.url,data=self.data,headers=self.post_headers)
        xml =str(r.text)
        print(xml)
        re_e = r'FailedCount>(\d+)'
        res = re.compile(re_e)
        fail_info =re.findall(res, xml)

        try:
            if int(fail_info[0]):

                log_set(name='fix', msg='fix is fail ,do it youself,id =%s' % self.xc_id)
                return False
            else:
                print('fixied')
                log_set(name='fix', msg=' fix is ok!,id =%s,%s,%s,%s,%s,%s'% (self.date,self.DepartPort,self.ArrivePort,self.Flight_No,self.price,self.xc_id))
                print(self.date,self.DepartPort,self.ArrivePort,self.Flight_No,self.price,self.xc_id)
                update2_xcfly(self.date,self.DepartPort,self.ArrivePort,self.Flight_No,self.price,self.xc_id,self.ivent)
                print('fix is successs,%s' % self.id)
                return True

        except:
              #log_set(name='del_info', msg='[Del_XC_Fail2]deal error, please check!,id =%s'% self.id)
              #return False
              pass
Example #2
0
    def compare(self,feiba_info,day,deptCd,arrCd):
        """
	    feiba_inf    {'KN5851': ('A', '578.0')}
		xc[('139.94', 'KN2908'), ('397.09', 'KN2906')
		"""
        push_info=''
        info_list = self.get_data()
        print('xc_info',info_list)
        print('feba_info',feiba_info)
        if info_list:
           for xc in info_list:
               fligh_name_feiba = (list(feiba_info)[0].encode('utf-8')).lower()
               xc_flight_no = (xc[2]).encode('utf-8').lower()

               print(xc_flight_no,fligh_name_feiba)
               if xc_flight_no == fligh_name_feiba:    # flight
                   # print('有对应的航班:%s'%(xc[1]).upper())
                   log_set(name='class_xiecheng', msg ='[xiecheng]有对应的航班:%s'%(xc[1]).upper())
                   feiba_price = feiba_info[fligh_name_feiba.upper()][1].encode('utf-8')
                   inVent =feiba_info[fligh_name_feiba.upper()][0].encode('utf-8')
                   print(inVent)
                   xc_id = get2_id_from_info(self.yearDate, self.DepartPort,self.ArrivePort,fligh_name_feiba[2:])

                   #if 778.0 - float(feiba_price) >6:
                   print('----------',float(xc[1]),float(feiba_price))
                   if float(xc[1]) - float(feiba_price) >6:     #推送条件

                       # if self.tag in (1,'1'):  # yi tou
                       #     print(str(xc[0]),xc_id)
                       #     old_xc_price = get2_pri_from_info(self.yearDate, self.DepartPort,self.ArrivePort,fligh_name_feiba[2:])
                       #
                       #     if not (str(xc[0])).encode('utf-8') == xc_id:   #bie ren gai
                       #         print('old_price'+str(old_xc_price)+'NEW PRICE'+str(float(xc[1])))
                       #         xx =float(xc[1])-float(old_xc_price)
                       #         if (not (str(xx) == '0.1')):  # bu shi wo
                       #             print(xx)
                       #             # log_set(name='fix_byself',msg=('do fix,old_price:'+str(old_xc_price)+'NEW PRICE:'+str(float(xc[1])))+':'+str(xc[0])+':'+str(xc_id))
                       #             print('will do fix')
                       #             price = str(float(xc[1])-0.1)
                       #             print(xc_id,self.yearDate,price,self.DepartPort,self.ArrivePort,fligh_name_feiba[2:])
                       #             log_set(name='fix',msg='will fix price ne:%s,old:%s'%(price,old_xc_price))
                       #             fix_work(xc_id,self.yearDate,price,self.DepartPort,self.ArrivePort,fligh_name_feiba[2:])
                       #         else:
                       #             print('yanshi ,bugaijia')
                       #             log_set(name='class_xiecheng', msg='yanshi bu gai jia,old_price'+ str(old_xc_price)+'NEW PRICE'+str(float(xc[1])))
                       #
                       #
                       #     else:
                       #         print('woziji bu gai jia')
                       #         log_set(name='class_xiecheng', msg='woziji bu gai jia,old_price'+ str(old_xc_price)+'NEW PRICE'+str(float(xc[1])))
                       #         pass #shi wo

                       if self.tag in (0,'0'):  # new come
                           # save_xc_info(self.yearDate, self.DepartPort,self.ArrivePort,xc[2], str(float(feiba_price)),inVent,xc_id=xc[0])
                           Flight_No=(xc[2][2:]).encode('utf-8')
                           print('old',xc_id)
                           if not xc_id:   # never push
                               XC_send(YearMonthDate1=day, DepartPort=deptCd,ArrivePort=arrCd, Flight_No=Flight_No,Flight_Price=float(xc[1]),feiba_inVent=inVent,feiba_price=feiba_price)
                               #save_xc_info(YearMonthDate1=day, DepartPort=deptCd,ArrivePort=arrCd, Flight_No=xc[1],Flight_Price=float(xc[0]),inVent=int(feiba_info[(xc[1]).upper()][0]))
                               push_info = 'yearDate:%s,DepartPort:%s,ArrivePort%s##%s:%s will push !!!!!!'%(self.yearDate,self.DepartPort,self.ArrivePort,xc[0], xc[1])
                               log_set(name='class_xiecheng',msg=push_info)
                           else:
                               print('update2')
                               update2_xcfly(day,deptCd,arrCd, Flight_No,float(xc[1]),xc_id,inVent)


                   else:
                       print('携程数据中没有推送符合条件的航班信息,need delete zhe push order')
                       log_set(name='class_xiecheng', msg = '[xiecheng]携程数据中没有推送符合条件的航班信息need delete zhe push order,%s,%s,xiecheng:%s,feiba:%s'%(xc[2],self.yearDate,xc[1],feiba_price))
                       if self.tag in (1,'1'):
                           print('delete the pushed order')
                           log_set(name='fix_info',msg='delete the pushed order:%s,%s,%s,%s,%s,%s'%(self.yearDate, self.DepartPort,self.ArrivePort,fligh_name_feiba[2:],feiba_price,xc[1]))
                           xc_id = get2_id_from_info(self.yearDate, self.DepartPort,self.ArrivePort,fligh_name_feiba[2:])
                           print('idddddd',xc_id)
                           del_work(xc_id)

               else:
                    print('携程没有相应的航班')
        else:
            print('can not get data form xiecheng')
            log_set(name='class_xiecheng',msg='can not ge date from xiecheng')
        return push_info
Example #3
0
    def push_data(self):
        r = requests.post(url=self.url, data=self.data, headers=self.post_headers)
        xml_str = (r.text).lower()
        # print(xml_str)

        ret = r"<successcount>(\d)</successcount>"
        ret = re.compile(ret)
        info_list = re.findall(ret, xml_str)
        if len(info_list[0]):
            print("投放成功")

            ret_id = r"<successlist><id>(\d+)"
            ret_id = re.compile(ret_id)
            id_list = re.findall(ret_id, xml_str)
            # print(info_list)

            xc_id_new = str(id_list[0])
            old_xc_id = get2_id_from_info(self.yearDate, self.DepartPort, self.ArrivePort, self.Flight_No)
            print(old_xc_id)
            if not old_xc_id:
                save_xc_info(
                    self.yearDate,
                    self.DepartPort,
                    self.ArrivePort,
                    self.Flight_No,
                    self.feiba_price,
                    self.feiba_inVent,
                    xc_id=xc_id_new,
                )
                save2_xc_info(
                    self.yearDate,
                    self.DepartPort,
                    self.ArrivePort,
                    self.Flight_No,
                    self.inVent,
                    xc_id_new,
                    self.Flight_Price,
                )
            else:
                update2_xcfly(
                    self.yearDate,
                    self.DepartPort,
                    self.ArrivePort,
                    self.Flight_No,
                    self.Flight_Price,
                    xc_id_new,
                    self.inVent,
                )

            log_set(
                name="send",
                msg="[send] ok!,%s,%s,%s,%s,%s,%s"
                % (self.Flight_No, xc_id_new, self.inVent, self.DepartPort, self.ArrivePort, self.yearDate),
            )
            return True
        else:
            # print('失败')
            log_set(
                name="send",
                msg="[send_fail] %s,%s,%s,%s,%s"
                % (self.Flight_No, self.inVent, self.DepartPort, self.ArrivePort, self.yearDate),
            )
            return False