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)
def query_by_date(self, date): """ 通过日期进行查询 :return: """ 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') return self.query.session.get(url)
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