Exemple #1
0
 def sendChechFace(self):
     chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"),
                                                self.data_apr())
     if not chechFaceRsp.get("status"):
         print("".join(chechFaceRsp.get("messages"))
               or chechFaceRsp.get("validateMessages"))
         wrapcache.set(key=f"hb{self.train_no}",
                       value=datetime.datetime.now(),
                       timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60)
         return
     data = chechFaceRsp["data"]
     if not data.get("face_flag"):
         print("".join(chechFaceRsp.get("messages"))
               or chechFaceRsp.get("validateMessages"))
         if data.get("face_check_code") == "14":
             """
             未通过人脸核验
             """
             raise ticketConfigException(
                 "通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验"
             )
         elif data.get("face_check_code") in ["12", "02"]:
             """
             系统忙,请稍后再试!
             """
             print("系统忙,请稍后再试!")
             wrapcache.set(key=f"hb{self.train_no}",
                           value=datetime.datetime.now(),
                           timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60)
         elif data.get("face_check_code") in ["03", "13"]:
             """
             证件信息审核失败,请检查所填写的身份信息内容与原证件是否一致。
             """
             raise ticketConfigException("证件信息审核失败,请检查所填写的身份信息内容与原证件是否一致。")
         elif data.get("face_check_code") in ["01", "11"]:
             """
             证件信息正在审核中,请您耐心等待,审核通过后可继续完成候补操作。
             """
             print("证件信息正在审核中,请您耐心等待,审核通过后可继续完成候补操作。")
             wrapcache.set(key=f"hb{self.train_no}",
                           value=datetime.datetime.now(),
                           timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60)
     g = getSuccessRate(self.session, self.secretList)
     g.sendSuccessRate()
Exemple #2
0
 def submitOrderRequest(self, from_station, to_station):
     """
     提交车次信息
     车次对应字典
     {32: '商务座 ',
         31: '一等座 ',
         30: '二等座 ',
         25: '特等座 ',
         23: '软卧 ',
         28: '硬卧 ',
         29: '硬座 ',
         26: '无座 '
     } 参照station_seat()方法
     :return:
     """
     select_url = 'https://kyfw.12306.cn/otn/leftTicket/queryZ?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT'.format(self.station_date, from_station, to_station)
     station_ticket = json.loads(myurllib2.get(select_url), encoding='utf-8')
     value = station_ticket['data']
     if not value:
         print ('{0}-{1} 车次坐席查询为空...'.format(self.from_station, self.to_station))
     else:
         if value['result']:
             for i in value['result']:
                 ticket_info = i.split('|')
                 if ticket_info[11] == "Y" and ticket_info[1] == "预订":  # 筛选未在开始时间内的车次
                     for j in range(len(self._station_seat)):
                         is_ticket_pass = ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))]
                         # print self._station_seat[j]
                         if is_ticket_pass != '' and is_ticket_pass != '无' and ticket_info[3] in self.station_trains and is_ticket_pass != '*':  # 过滤有效目标车次
                             # tiket_values = [k for k in value['map'].values()]
                             self.secretStr = ticket_info[0]
                             train_no = ticket_info[3]
                             print ('车次: ' + train_no + ' 始发车站: ' + self.from_station + ' 终点站: ' +
                                    self.to_station + ' ' + self._station_seat[j].encode("utf8") + ':' + ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))])
                             if self.ticket_black_list.has_key(train_no) and (datetime.datetime.now() - self.ticket_black_list[train_no]).seconds/60 < int(self.ticket_black_list_time):
                                 print("该车次{} 正在被关小黑屋,跳过此车次".format(train_no))
                                 break
                             else:
                                 print ('正在尝试提交订票...')
                                 if self.check_user():
                                     self.submit_station()
                                     self.getPassengerTicketStr(self._station_seat[j].encode("utf8"))
                                     self.getRepeatSubmitToken()
                                     self.user_info = self.getPassengerDTOs()
                                     if self.checkOrderInfo(train_no, self._station_seat[j].encode("utf8")):
                                             break
                         else:
                             pass
                     print "当前车次{0} 查询无符合条件坐席,正在重新查询".format(ticket_info[3])
                 elif ticket_info[11] == "N":
                     print("当前车次{0} 无票".format(ticket_info[3]))
                 else:
                     print("当前这次还处于待售状态,请耐心等待")
                     time.sleep(self.expect_refresh_interval)
         else:
             raise ticketConfigException("车次配置信息有误,请检查")
Exemple #3
0
 def sendChechFace(self):
     chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr())
     if not chechFaceRsp.get("status"):
         print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages"))
         return
     data = chechFaceRsp["data"]
     if not data.get("face_flag") and data.get("face_check_code") == 14:
         """
         未通过人脸核验
         """
         raise ticketConfigException("通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验")
     g = getSuccessRate(self.session, self.secretList)
     g.sendSuccessRate()
 def cdn_certification(self):
     """
     cdn 认证
     :return:
     """
     if self.is_cdn == 1:
         CDN = CDNProxy()
         all_cdn = CDN.all_cdn()
         if all_cdn:
             print(u"开启cdn查询")
             print(u"本次待筛选cdn总数为{}".format(len(all_cdn)))
             t = threading.Thread(target=self.cdn_req, args=(all_cdn, ))
             t.start()
         else:
             raise ticketConfigException(u"cdn列表为空,请先加载cdn")
     else:
         pass
 def cdn_certification(self):
     """
     cdn 认证
     :return:
     """
     if self.is_cdn == 1:
         CDN = CDNProxy()
         all_cdn = CDN.all_cdn()
         if all_cdn:
             print(u"开启cdn查询")
             print(u"本次待筛选cdn总数为{}".format(len(all_cdn)))
             t = threading.Thread(target=self.cdn_req, args=(all_cdn,))
             t.start()
         else:
             raise ticketConfigException(u"cdn列表为空,请先加载cdn")
     else:
         pass
Exemple #6
0
 def cdn_certification(self):
     """
     cdn 认证
     :return:
     """
     if self.is_cdn == 1:
         CDN = CDNProxy()
         all_cdn = CDN.all_cdn()
         if all_cdn:
             print(u"由于12306网站策略调整,cdn功能暂时关闭。")
             # print(u"开启cdn查询")
             # print(u"本次待筛选cdn总数为{}, 筛选时间大约为5-10min".format(len(all_cdn)))
             # t = threading.Thread(target=self.cdn_req, args=(all_cdn,))
             # t2 = threading.Thread(target=self.set_cdn, args=())
             # t.start()
             # t2.start()
         else:
             raise ticketConfigException(u"cdn列表为空,请先加载cdn")
Exemple #7
0
def checkDate(station_dates):
    """
    检查日期是否合法
    :param station_dates:
    :return:
    """
    today = datetime.datetime.now()
    maxDay = (today + datetime.timedelta(maxDate)).strftime("%Y-%m-%d")
    for station_date in station_dates[::-1]:
        date = datetime.datetime.strftime(datetime.datetime.strptime(station_date, "%Y-%m-%d"), "%Y-%m-%d")
        if date < today.strftime("%Y-%m-%d") or date > maxDay:
            print(u"警告:当前时间配置有小于当前时间或者大于最大时间: {}, 已自动忽略".format(station_date))
            station_dates.remove(station_date)
            if not station_dates:
                print(u"当前日期设置无符合查询条件的,已被全部删除,请查证后添加!!!")
                raise ticketConfigException(u"当前日期设置无符合查询条件的,已被全部删除,请查证后添加!!!")
        else:
            station_dates[station_dates.index(station_date)] = date
    return station_dates
Exemple #8
0
 def sendChechFace(self):
     chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"),
                                                self.data_apr())
     if not chechFaceRsp.get("status"):
         print("".join(chechFaceRsp.get("messages"))
               or chechFaceRsp.get("validateMessages"))
         wrapcache.set(key=f"hb{self.train_no}",
                       value=datetime.datetime.now(),
                       timeout=TickerConfig.TICKET_BLACK_LIST_TIME * 60)
         return
     data = chechFaceRsp["data"]
     if not data.get("face_flag"):
         """
         未通过人脸核验
         """
         raise ticketConfigException(
             "通过人证一致性核验的用户及激活的“铁路畅行”会员可以提交候补需求,请您按照操作说明在铁路12306app.上完成人证核验")
     g = getSuccessRate(self.session, self.secretList)
     g.sendSuccessRate()