优化候补逻辑

pull/328/head
xianping.wen 2019-09-07 11:36:12 +08:00
parent 4f7d9807eb
commit 7a26f8447a
7 changed files with 37 additions and 32 deletions

View File

@ -13,8 +13,9 @@ TICKET_TYPE = 2
J_Z_PARAM = "2019-09-28#22#59" J_Z_PARAM = "2019-09-28#22#59"
# 出发日期(list) "2018-01-06", "2018-01-07" # 出发日期(list) "2018-01-06", "2018-01-07"
# ps: 日期如果是单日一定要前面补个0正确做法2019-01-01 错误做法2019-1-1
STATION_DATES = [ STATION_DATES = [
"2019-10-01" "2019-09-25"
] ]
# 填入需要购买的车次(list)"G1353" # 填入需要购买的车次(list)"G1353"
@ -23,10 +24,10 @@ STATION_TRAINS = [
] ]
# 出发城市,比如深圳北,就填深圳就搜得到 # 出发城市,比如深圳北,就填深圳就搜得到
FROM_STATION = "深圳北" FROM_STATION = ""
# 到达城市 比如深圳北,就填深圳就搜得到 # 到达城市 比如深圳北,就填深圳就搜得到
TO_STATION = "隆回" TO_STATION = ""
# 座位(list) 多个座位ex: # 座位(list) 多个座位ex:
# "商务座", # "商务座",
@ -39,7 +40,7 @@ TO_STATION = "隆回"
# "无座", # "无座",
# "动卧", # "动卧",
SET_TYPE = [ SET_TYPE = [
"二等座", "",
] ]
# 当余票小于乘车人,如果选择优先提交,则删减联系人和余票数一致在提交 # 当余票小于乘车人,如果选择优先提交,则删减联系人和余票数一致在提交
@ -77,7 +78,7 @@ IS_AUTO_CODE = True
# password: "授权码" # password: "授权码"
# host: "smtp.qq.com" # host: "smtp.qq.com"
EMAIL_CONF = { EMAIL_CONF = {
"IS_MAIL": True, "IS_MAIL": False,
"email": "", "email": "",
"notice_email_list": "", "notice_email_list": "",
"username": "", "username": "",
@ -111,13 +112,13 @@ IS_PROXY = 0
# 预售放票时间, 如果是捡漏模式,可以忽略此操作 # 预售放票时间, 如果是捡漏模式,可以忽略此操作
OPEN_TIME = "13:00:00" OPEN_TIME = "13:00:00"
# 1=使用selenium获取devicesID # 1=使用selenium获取devicesID
# 2=使用网页端/otn/HttpZF/logdevice获取devicesId这个接口的算法目前可能有点问题如果登录一直302的请改为配置1 # 2=使用网页端/otn/HttpZF/logdevice获取devicesId这个接口的算法目前可能有点问题如果登录一直302的请改为配置1
COOKIE_TYPE = 1 COOKIE_TYPE = 1
# 如果COOKIE_TYPE=1则需配置chromeDriver路径,下载地址http://chromedriver.storage.googleapis.com/index.html # 如果COOKIE_TYPE=1则需配置chromeDriver路径(注意是填你机器本地chromeDriver的路径这个地方一定要改),下载地址http://chromedriver.storage.googleapis.com/index.html
# chromedriver配置版本只要和chrome的大版本匹配就行 # chromedriver配置版本只要和chrome的大版本匹配就行
CHROME_PATH = "/Users/wenxianping/Downloads/chromedriver" # 如果是windows,最好在路径加上r, ex: r"/Users/wenxianping/Downloads/chromedriver"
CHROME_PATH = ""
PASSENGER_TICKER_STR = { PASSENGER_TICKER_STR = {
'一等座': 'M', '一等座': 'M',
@ -132,4 +133,4 @@ PASSENGER_TICKER_STR = {
} }
# 软件版本 # 软件版本
RE_VERSION = "1.1.105" RE_VERSION = "1.1.106"

View File

@ -173,3 +173,7 @@
- 恢复TICKET_TYPE字段1=刷票 2=候补+刷票 - 恢复TICKET_TYPE字段1=刷票 2=候补+刷票
- 优化候补逻辑 - 优化候补逻辑
- 候补订单只能在规定车次内候补 - 候补订单只能在规定车次内候补
- 2019.09.07更新
- 优化候补逻辑
- 去除敏感信息打印

View File

@ -107,7 +107,7 @@ def checkSleepTime(session):
now = datetime.datetime.now() now = datetime.datetime.now()
if now.hour >= maxRunStopTime or now.hour < maxRunTime: if now.hour >= maxRunStopTime or now.hour < maxRunTime:
print(u"12306休息时间本程序自动停止,明天早上六点将自动运行") print(u"12306休息时间本程序自动停止,明天早上六点将自动运行")
open_time = datetime.datetime(now.year, now.month, now.day, 6) open_time = datetime.datetime(now.year, now.month, now.day, maxRunTime)
if open_time < now: if open_time < now:
open_time += datetime.timedelta(1) open_time += datetime.timedelta(1)
time.sleep((open_time - now).seconds + round(random.uniform(1, 10))) time.sleep((open_time - now).seconds + round(random.uniform(1, 10)))

View File

@ -57,7 +57,7 @@ class select:
print(u"*" * 50) print(u"*" * 50)
print(f"检查当前版本为: {TickerConfig.RE_VERSION}") print(f"检查当前版本为: {TickerConfig.RE_VERSION}")
print(u"检查当前python版本为{}目前版本只支持3.6以上".format(sys.version.split(" ")[0])) print(u"检查当前python版本为{}目前版本只支持3.6以上".format(sys.version.split(" ")[0]))
print(u"12306刷票小助手最后更新于2019.09.03,请勿作为商业用途,交流群号:" print(u"12306刷票小助手最后更新于2019.09.07,请勿作为商业用途,交流群号:"
u" 1群286271084(已满)\n" u" 1群286271084(已满)\n"
u" 2群649992274(已满)\n" u" 2群649992274(已满)\n"
u" 3群632501142(已满)\n" u" 3群632501142(已满)\n"
@ -235,7 +235,7 @@ class select:
TickerConfig.TICKET_PEOPLES) TickerConfig.TICKET_PEOPLES)
sor.sendSubmitOrderRequest() sor.sendSubmitOrderRequest()
elif secretList: # 候补订单 elif secretList: # 候补订单
c = chechFace(self, secretList) c = chechFace(self, secretList, train_no)
c.sendChechFace() c.sendChechFace()
else: else:
random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2) random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2)

View File

@ -1,18 +1,21 @@
import datetime
import urllib import urllib
from collections import OrderedDict from collections import OrderedDict
from config.urlConf import urls from config.urlConf import urls
import TickerConfig import TickerConfig
from inter.GetSuccessRate import getSuccessRate from inter.GetSuccessRate import getSuccessRate
from myException.ticketConfigException import ticketConfigException from myException.ticketConfigException import ticketConfigException
import wrapcache
class chechFace: class chechFace:
def __init__(self, session, secretList): def __init__(self, session, secretList, train_no):
""" """
人脸识别 人脸识别
""" """
self.secretList = secretList self.secretList = secretList
self.session = session self.session = session
self.train_no = train_no
def data_apr(self): def data_apr(self):
""" """
@ -31,6 +34,8 @@ class chechFace:
chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr()) chechFaceRsp = self.session.httpClint.send(urls.get("chechFace"), self.data_apr())
if not chechFaceRsp.get("status"): if not chechFaceRsp.get("status"):
print("".join(chechFaceRsp.get("messages")) or chechFaceRsp.get("validateMessages")) 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 return
data = chechFaceRsp["data"] data = chechFaceRsp["data"]
if not data.get("face_flag"): if not data.get("face_flag"):

View File

@ -26,7 +26,7 @@ class checkUser:
if check_user.get("data", False): if check_user.get("data", False):
check_user_flag = check_user["data"]["flag"] check_user_flag = check_user["data"]["flag"]
if check_user_flag is True: if check_user_flag is True:
wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * CHENK_TIME) wrapcache.set("user_time", datetime.datetime.now(), timeout=60 * CHENK_TIME)
else: else:
if check_user['messages']: if check_user['messages']:
print(ticket.LOGIN_SESSION_FAIL.format(check_user['messages'])) print(ticket.LOGIN_SESSION_FAIL.format(check_user['messages']))

View File

@ -49,18 +49,6 @@ class query:
def check_is_need_train(self, ticket_info): def check_is_need_train(self, ticket_info):
return ticket_info[3] in self.station_trains return ticket_info[3] in self.station_trains
# def sendQueryFirst(self):
# """
# 首次请求打印接口车次信息
# :return:
# """
# for station_date in self.station_dates:
# 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,
# self.session.queryUrl)
# station_ticket = self.httpClint.send(select_url)
# values = station_ticket.get("data", "")
def sendQuery(self): def sendQuery(self):
""" """
查询 查询
@ -74,10 +62,6 @@ class query:
select_url["req_url"] = select_url["req_url"].format(station_date, self.from_station, self.to_station, select_url["req_url"] = select_url["req_url"].format(station_date, self.from_station, self.to_station,
self.session.queryUrl) self.session.queryUrl)
station_ticket = self.httpClint.send(select_url) station_ticket = self.httpClint.send(select_url)
# if station_ticket.get("c_url", ""):
# print(u"设置当前查询url为: {}".format(station_ticket.get("c_url", "")))
# self.session.queryUrl = station_ticket.get("c_url", "") # 重设查询接口
# continue
value = station_ticket.get("data", "") value = station_ticket.get("data", "")
if not value: if not value:
print(u'{0}-{1} 车次坐席查询为空查询url: https://kyfw.12306.cn{2}, 可以手动查询是否有票'.format( print(u'{0}-{1} 车次坐席查询为空查询url: https://kyfw.12306.cn{2}, 可以手动查询是否有票'.format(
@ -90,7 +74,16 @@ class query:
for i in value['result']: for i in value['result']:
ticket_info = i.split('|') ticket_info = i.split('|')
if self.session.flag: if self.session.flag:
print(f"车次:{ticket_info[3]} 出发站:{self.from_station_h} 到达站:{self.to_station_h} 历时:{ticket_info[10]} 商务/特等座:{ticket_info[32]} 一等座:{ticket_info[31]} 二等座:{ticket_info[30]} 动卧:{ticket_info[33]} 硬卧:{ticket_info[28]} 软座:{ticket_info[23]} 硬座:{ticket_info[29]} 无座:{ticket_info[26]} {ticket_info[1]}") print(f"车次:{ticket_info[3]} 出发站:{self.from_station_h} 到达站:{self.to_station_h} 历时:{ticket_info[10]}"
f" 商务/特等座:{ticket_info[32] or '--'}"
f" 一等座:{ticket_info[31] or '--'}"
f" 二等座:{ticket_info[30] or '--'}"
f" 动卧:{ticket_info[33] or '--'}"
f" 硬卧:{ticket_info[28] or '--'}"
f" 软座:{ticket_info[23] or '--'}"
f" 硬座:{ticket_info[29] or '--'}"
f" 无座:{ticket_info[26] or '--'}"
f" {ticket_info[1] or '--'}")
if ticket_info[1] == "预订" and self.check_is_need_train(ticket_info): # 筛选未在开始时间内的车次 if ticket_info[1] == "预订" and self.check_is_need_train(ticket_info): # 筛选未在开始时间内的车次
for j in self._station_seat: for j in self._station_seat:
is_ticket_pass = ticket_info[j] is_ticket_pass = ticket_info[j]
@ -156,12 +149,14 @@ class query:
""" """
# 如果最后一位为1则是可以候补的不知道这些正确嘛 # 如果最后一位为1则是可以候补的不知道这些正确嘛
nate = list(ticket_info[-1]) nate = list(ticket_info[-1])
if wrapcache.get(f"hb{ticket_info[2]}"):
continue
for set_type in TickerConfig.SET_TYPE: for set_type in TickerConfig.SET_TYPE:
if TickerConfig.PASSENGER_TICKER_STR[set_type] not in nate: if TickerConfig.PASSENGER_TICKER_STR[set_type] not in nate:
print(f"当前订单可以候补,候补位置为: {set_type}, 尝试提交候补订单")
return { return {
"secretList": ticket_info[0], "secretList": ticket_info[0],
"seat": [set_type], "seat": [set_type],
"train_no": ticket_info[2],
"status": True, "status": True,
} }
else: else: