Ejemplo n.º 1
0
 def query_by_date(self, date):
     """
     通过日期进行查询
     :return:
     """
     from py12306.helpers.cdn import Cdn
     QueryLog.add_log(('\n' if not is_main_thread() else '') +
                      QueryLog.MESSAGE_QUERY_START_BY_DATE.format(
                          date, self.left_station, self.arrive_station))
     url = LEFT_TICKETS.get('url').format(
         left_date=date,
         left_station=self.left_station_code,
         arrive_station=self.arrive_station_code,
         type=self.query.api_type)
     print("ticket query url=%s" % url)
     if Config.is_cdn_enabled() and Cdn().is_ready:
         self.is_cdn = True
         print("12306 cdn is enabled.")
         return self.query.session.cdn_request(url,
                                               timeout=self.query_time_out,
                                               allow_redirects=False)
     self.is_cdn = False
     return self.query.session.get(url,
                                   timeout=self.query_time_out,
                                   allow_redirects=False)
Ejemplo n.º 2
0
 def start(self):
     if not Config.is_cdn_enabled(): return
     self.load_items()
     CommonLog.add_quick_log(
         CommonLog.MESSAGE_CDN_START_TO_CHECK.format(len(
             self.items))).flush()
     self.restore_items()
     for i in range(self.thread_num):  # 多线程
         create_thread_and_run(jobs=self,
                               callback_name='check_available',
                               wait=False)
Ejemplo n.º 3
0
    def query_by_date(self, date):
        """
        通过日期进行查询
        :return:
        """
        from py12306.helpers.cdn import Cdn
        QueryLog.add_log(('\n' if not is_main_thread() else '') +
                         QueryLog.MESSAGE_QUERY_START_BY_DATE.format(
                             date, self.left_station, self.arrive_station))
        url = LEFT_TICKETS.get('url').format(
            left_date=date,
            left_station=self.left_station_code,
            arrive_station=self.arrive_station_code,
            type='leftTicket/queryZ')
        if Config.is_cdn_enabled() and Cdn().is_ready:
            self.is_cdn = True
            return self.query.session.cdn_request(url,
                                                  timeout=self.query_time_out,
                                                  allow_redirects=False)
        self.is_cdn = False
        if Config.is_zf():
            headers = ZFProxyUtil.getProxySign()
            proxy = ZFProxyUtil.getProxy()
            yp_by_data = self.query.session.get(url,
                                                headers=headers,
                                                proxies=proxy,
                                                verify=False,
                                                allow_redirects=False,
                                                timeout=self.query_time_out)
        else:
            yp_by_data = self.query.session.get(url,
                                                verify=False,
                                                allow_redirects=False,
                                                timeout=self.query_time_out)

        return yp_by_data