1、优化查询策略

2、快读下单修复
3、关闭cdn功能
pull/49/merge
wenxianping 6 years ago
parent 2f2d62af19
commit c9de32463a

@ -123,8 +123,8 @@ class select:
for i in range(len(cdn) - 1):
http = HTTPClient()
urls = self.urls["loginInit"]
start_time = datetime.datetime.now()
http.cdn = cdn[i].replace("\n", "")
start_time = datetime.datetime.now()
rep = http.send(urls)
if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 500:
print("加入cdn {0}".format(cdn[i].replace("\n", "")))
@ -140,20 +140,19 @@ class select:
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,))
t2 = threading.Thread(target=self.set_cdn, args=())
t.start()
t2.start()
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")
else:
pass
def main(self):
self.cdn_certification()
l = liftTicketInit(session=self)
l = liftTicketInit(self)
l.reqLiftTicketInit()
self.call_login()
checkUser(self).sendCheckUser()
@ -237,7 +236,7 @@ class select:
self.station_trains),
(
datetime.datetime.now() - start_time).microseconds / 1000,
self.httpClint.cdn,
wrapcache.get("cdn"),
len(
self.cdn_list),
random_time)

@ -24,17 +24,17 @@ class autoSubmitOrderRequest:
stationTrainCode,
leftTicket,
set_type,):
self.set_type = set_type
self.secretStr = urllib.unquote(secretStr)
self.train_date = train_date
self.query_from_station_name = query_from_station_name
self.query_to_station_name = query_to_station_name
self.passengerTicketStr = passengerTicketStr
self.passengerTicketStr = passengerTicketStr.rstrip("_{0}".format(self.set_type))
self.oldPassengerStr = oldPassengerStr
self.session = session
self.train_no = train_no
self.stationTrainCode = stationTrainCode
self.leftTicket = leftTicket
self.set_type = set_type
def data_par(self):
"""

@ -11,9 +11,10 @@ class checkUser:
def sendCheckUser(self):
"""
检查用户登录, 检查间隔为分钟
检查用户登录, 检查间隔为2分钟
:return:
"""
CHENK_TIME = 2
if wrapcache.get("user_time") is None:
check_user_url = self.session.urls["check_user_url"]
data = {"_json_att": ""}
@ -21,13 +22,13 @@ class checkUser:
if check_user.get("data", False):
check_user_flag = check_user["data"]["flag"]
if check_user_flag is True:
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * 5)
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * CHENK_TIME)
else:
if check_user['messages']:
print (ticket.LOGIN_SESSION_FAIL.format(check_user['messages']))
self.session.call_login()
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * 5)
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * CHENK_TIME)
else:
print (ticket.LOGIN_SESSION_FAIL.format(check_user['messages']))
self.session.call_login()
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * 5)
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * CHENK_TIME)

@ -1,8 +1,13 @@
# coding=utf-8
import copy
import datetime
import random
import wrapcache
from config import urlConf
from config.TicketEnmu import ticket
from myUrllib.httpUtils import HTTPClient
class query:
@ -13,6 +18,8 @@ class query:
def __init__(self, session, from_station, to_station, from_station_h, to_station_h, _station_seat, station_trains,
ticke_peoples_num, station_dates=None,):
self.session = session
self.httpClint = HTTPClient()
self.urls = urlConf.urls
self.from_station = from_station
self.to_station = to_station
self.from_station_h = from_station_h
@ -45,9 +52,9 @@ class query:
:return:
"""
for station_date in self.station_dates:
select_url = copy.copy(self.session.urls["select_url"])
select_url = copy.copy(self.urls["select_url"])
select_url["req_url"] = select_url["req_url"].format(station_date, self.from_station, self.to_station)
station_ticket = self.session.httpClint.send(select_url)
station_ticket = self.httpClint.send(select_url)
value = station_ticket.get("data", "")
if not value:
print (u'{0}-{1} 车次坐席查询为空'.format(self.from_station_h, self.to_station_h))
@ -80,15 +87,16 @@ class query:
if wrapcache.get(train_no):
print(ticket.QUERY_IN_BLACK_LIST.format(train_no))
continue
else:
if ticket_num != "" and self.ticke_peoples_num > ticket_num:
if self.session.is_more_ticket:
print(u"余票数小于乘车人数,当前余票数: {}, 删减人车人数到: {}".format(ticket_num, ticket_num))
is_more_ticket_num = ticket_num
else:
print(u"余票数小于乘车人数,当前设置不提交,放弃此次提交机会")
continue
else:
print(u"设置乘车人数为: {}".format(self.ticke_peoples_num))
is_more_ticket_num = self.ticke_peoples_num
print (ticket.QUERY_C)
return {

@ -1,13 +1,11 @@
# -*- coding: utf8 -*-
import json
import socket
import urllib
from collections import OrderedDict
from time import sleep
import requests
from config import logger
import wrapcache
def _set_header_default():
@ -102,6 +100,8 @@ class HTTPClient(object):
req_url = urls.get("req_url", "")
re_try = urls.get("re_try", 0)
s_time = urls.get("s_time", 0)
is_cdn = urls.get("is_cdn", False)
is_test_cdn = urls.get("is_test_cdn", False)
error_data = {"code": 99999, "message": u"重试次数达到上限"}
if data:
method = "post"
@ -114,8 +114,14 @@ class HTTPClient(object):
logger.log(
u"url: {0}\n入参: {1}\n请求方式: {2}\n".format(req_url, data, method, ))
self.setHeadersHost(urls["Host"])
if self.cdn:
url_host = self.cdn
if is_test_cdn:
url_host = self._cdn
elif is_cdn:
cdn = wrapcache.get("cdn")
if cdn:
url_host = cdn
else:
url_host = urls["Host"]
else:
url_host = urls["Host"]
for i in range(re_try):

Loading…
Cancel
Save