增加余票不足优先提交功能

pull/187/head
wenxianping 2019-01-12 15:26:02 +08:00
parent 109967ca70
commit c68cc016e0
13 changed files with 200 additions and 158 deletions

View File

@ -81,6 +81,7 @@
- 感谢一下小伙伴对本项目提供的帮助
- @sun7127@126.com
- @ 才
- @MonsterTan
- 以及所有为此项目提供pr的同学
- [更新日志](Update.md)

View File

@ -134,3 +134,6 @@
- mac和linux服务器自动对点
- 增加预售踩点查询下单经测试误差在0.004s
- 2019.01.12更新
- 增加对python3语法的支持
- 删除校验时间很多机器不兼容的问题win10会阻拦对时功能导致大面积报错如果是预售为了不耽误宝贵的时间请手动对时

View File

@ -76,4 +76,4 @@ class CDNProxy:
if __name__ == '__main__':
cdn = CDNProxy()
cdn.open_cdn_file()
print(cdn.open_cdn_file())

View File

@ -15,21 +15,21 @@ def autoSynchroTime():
hosts = ['ntp1.aliyun.com', 'ntp2.aliyun.com', 'ntp3.aliyun.com', 'ntp4.aliyun.com', 'cn.pool.ntp.org']
print(u"正在同步时间请耐心等待30秒左右")
print(u"正在同步时间请耐心等待30秒左右,如果下面有错误发送,可以忽略!!")
print(u"系统当前时间{}".format(str(datetime.datetime.now())[:22]))
system = platform.system()
if system == "Windows": # windows 同步时间未测试过参考地址https://www.jianshu.com/p/92ec15da6cc3
for host in hosts:
os.system('w32tm /register')
os.system('net start w32time')
os.system('w32tm /config /manualpeerlist:"{}" /syncfromflags:manual /reliable:yes /update'.format(host))
os.system('ping -n 3 127.0.0.1 >nul')
sin = os.system('w32tm /resync')
os.popen('w32tm /register')
os.popen('net start w32time')
os.popen('w32tm /config /manualpeerlist:"{}" /syncfromflags:manual /reliable:yes /update'.format(host))
os.popen('ping -n 3 127.0.0.1 >nul')
sin = os.popen('w32tm /resync')
if sin is 0:
break
else: # mac同步地址如果ntpdate未安装brew install ntpdate linux 安装 yum install -y ntpdate
for host in hosts:
sin = os.system('ntpdate {}'.format(host))
sin = os.popen('ntpdate {}'.format(host))
if sin is 0:
break
print(u"同步后时间:{}".format(str(datetime.datetime.now())[:22]))

View File

@ -11,7 +11,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
@ -23,7 +23,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
@ -36,7 +36,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": False,
"is_json": False,
@ -49,7 +49,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": False,
"is_json": False,
@ -62,7 +62,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
@ -73,7 +73,7 @@ urls = {
"Referer": "https://kyfw.12306.cn/otn/index/init",
"Host": "kyfw.12306.cn",
"re_try": 1,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": False,
"is_json": False,
@ -84,7 +84,7 @@ urls = {
"Referer": "https://kyfw.12306.cn/otn/index/init",
"Host": "kyfw.12306.cn",
"re_try": 1,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": False,
"is_test_cdn": True,
@ -96,7 +96,7 @@ urls = {
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
"Host": "kyfw.12306.cn",
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.01,
"is_logger": False,
"is_json": False,
@ -107,7 +107,7 @@ urls = {
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
"Host": "kyfw.12306.cn",
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
@ -119,7 +119,7 @@ urls = {
"Host": "kyfw.12306.cn",
"Content-Type": 1,
"re_try": 10,
"re_time": 0.1,
"re_time": 1,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
@ -337,6 +337,18 @@ urls = {
"is_logger": True,
"is_json": True,
},
"loginAysnSuggest": { # 快速订单排队
"req_url": "/otn/login/loginAysnSuggest",
"req_type": "post",
"Referer": "https://kyfw.12306.cn/otn/leftTicket/init",
"Content-Type": 1,
"Host": "kyfw.12306.cn",
"re_try": 10,
"re_time": 0.01,
"s_time": 0.1,
"is_logger": True,
"is_json": True,
},
"cdn_host": {
"req_url": "http://ping.chinaz.com/kyfw.12306.cn",
"req_type": "post"

View File

@ -7,7 +7,10 @@ class RClient(object):
def __init__(self, username, password):
self.username = username
try:
self.password = md5(password).hexdigest()
except TypeError:
self.password = md5(password.encode('utf-8')).hexdigest()
self.soft_id = '96061'
self.soft_key = '6facb9da7bb645ad9c4a229464b2cf89'
self.base_params = {

View File

@ -70,7 +70,10 @@ class select:
to_station = ticket_info_config["set"]["to_station"]
station_dates = ticket_info_config["set"]["station_dates"]
set_names = ticket_info_config["set"]["set_type"]
try:
set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]]
except KeyError:
set_type = [seat_conf[x] for x in ticket_info_config["set"]["set_type"]]
is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
station_trains = ticket_info_config["set"]["station_trains"]
@ -134,8 +137,12 @@ class select:
for i in range(0, len(info)):
n_info = info[i].split('|')
station_name[n_info[1]] = n_info[2]
try:
from_station = station_name[from_station.encode("utf8")]
to_station = station_name[to_station.encode("utf8")]
except KeyError:
from_station = station_name[from_station]
to_station = station_name[to_station]
return from_station, to_station
def call_login(self, auth=False):
@ -182,7 +189,8 @@ class select:
raise ticketConfigException(u"cdn列表为空请先加载cdn")
def main(self):
autoSynchroTime() # 同步时间
# autoSynchroTime() # 同步时间
try:
self.cdn_certification()
l = liftTicketInit(self)
l.reqLiftTicketInit()
@ -193,8 +201,9 @@ class select:
t.start()
from_station, to_station = self.station_table(self.from_station, self.to_station)
num = 0
s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples)
s.sendGetPassengerDTOs()
while 1:
try:
num += 1
now = datetime.datetime.now() # 感谢群里大佬提供整点代码
configCommon.checkSleepTime(self) # 晚上到点休眠
@ -282,19 +291,14 @@ class select:
time.sleep(random_time)
except PassengerUserException as e:
print(e)
break
except ticketConfigException as e:
print(e)
break
except ticketIsExitsException as e:
print(e)
break
except ticketNumOutException as e:
print(e)
break
except UserPasswordException as e:
print(e)
break
except ValueError as e:
if e == "No JSON object could be decoded":
print(u"12306接口无响应正在重试")

View File

@ -25,7 +25,10 @@ class autoSubmitOrderRequest:
leftTicket,
set_type,):
self.set_type = set_type
try:
self.secretStr = urllib.unquote(secretStr)
except AttributeError:
self.secretStr = urllib.parse.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

View File

@ -1,4 +1,6 @@
# coding=utf-8
import json
from config.TicketEnmu import ticket
from myException.PassengerUserException import PassengerUserException
import wrapcache
@ -14,19 +16,21 @@ class getPassengerDTOs:
获取乘客信息
:return:
"""
def __init__(self, session, ticket_peoples, set_type, is_more_ticket_num):
def __init__(self, session, ticket_peoples=None, set_type=None, is_more_ticket_num=None):
"""
:param session: 登录实例
:param ticket_peoples: 乘客
:param set_type: 坐席
"""
if ticket_peoples is None:
ticket_peoples = []
self.session = session
self.ticket_peoples = ticket_peoples
self.is_more_ticket_num = is_more_ticket_num
self.set_type = set_type.encode("utf8")
self.set_type = set_type
def sendGetPassengerDTOs(self):
getPassengerDTOsResult = self.session.httpClint.send(self.session.urls["get_passengerDTOs"], {})
getPassengerDTOsResult = self.session.httpClint.send(self.session.urls["get_passengerDTOs"], json.dumps({"_json_att": ""}))
if getPassengerDTOsResult.get("data", False) and getPassengerDTOsResult["data"].get("normal_passengers", False):
normal_passengers = getPassengerDTOsResult['data']['normal_passengers']
_normal_passenger = [normal_passengers[i] for i in range(len(normal_passengers)) if
@ -38,8 +42,10 @@ class getPassengerDTOs:
elif getPassengerDTOsResult.get('messages', False):
print(getPassengerDTOsResult.get('messages', False))
else:
print(getPassengerDTOsResult)
raise PassengerUserException(ticket.DTO_NOT_FOUND)
print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!")
print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!")
print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!")
# raise PassengerUserException(ticket.DTO_NOT_FOUND)
def getPassengerTicketStr(self, set_type):
"""
@ -57,7 +63,6 @@ class getPassengerDTOs:
'软座': 2,
'软卧': 4,
'硬卧': 3,
'动卧': 1,
}
return str(passengerTicketStr[set_type.replace(' ', '')])

View File

@ -1,5 +1,6 @@
# coding=utf-8
import datetime
import sys
import time
from collections import OrderedDict
import wrapcache
@ -46,7 +47,10 @@ class getQueueCount:
:return:
"""
if sys.version_info.major is 2:
new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" "))
else:
new_train_date = list(filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")))
data = OrderedDict()
data['train_date'] = "{0} {1} 0{2} {3} 00:00:00 GMT+0800 (中国标准时间)".format(
new_train_date[0],

View File

@ -1,5 +1,6 @@
# coding=utf-8
import datetime
import sys
import time
from collections import OrderedDict
@ -56,7 +57,10 @@ class getQueueCountAsync:
- _json_att 没啥卵用还是带上吧
:return:
"""
if sys.version_info.major is 2:
new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" "))
else:
new_train_date = list(filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")))
data = OrderedDict()
data['train_date'] = "{0} {1} {2} {3} 00:00:00 GMT+0800 (中国标准时间)".format(
new_train_date[0],

View File

@ -103,7 +103,7 @@ class query:
if result:
for i in value['result']:
ticket_info = i.split('|')
if ticket_info[11] == "Y" and ticket_info[1].encode("utf8") == "预订": # 筛选未在开始时间内的车次
if ticket_info[11] == "Y" and ticket_info[1] == "预订": # 筛选未在开始时间内的车次
for j in self._station_seat:
is_ticket_pass = ticket_info[j]
if is_ticket_pass != '' and is_ticket_pass != '' and is_ticket_pass != '*' and self.check_is_need_train(

View File

@ -19,7 +19,10 @@ class submitOrderRequest:
def __init__(self, session, secretStr, from_station, to_station, train_no, set_type,
passengerTicketStrList, oldPassengerStr, train_date, ticke_peoples):
self.session = session
self.secretStr = secretStr
try:
self.secretStr = urllib.unquote(secretStr)
except AttributeError:
self.secretStr = urllib.parse.unquote(secretStr)
self.from_station = from_station
self.to_station = to_station
self.to_station = to_station
@ -34,7 +37,7 @@ class submitOrderRequest:
"""
:return:
"""
data = [('secretStr', urllib.unquote(self.secretStr)), # 字符串加密
data = [('secretStr', self.secretStr), # 字符串加密
('train_date', self.train_date), # 出发时间
('back_train_date', time()), # 返程时间
('tour_flag', 'dc'), # 旅途类型