mirror of https://github.com/testerSunshine/12306
修改时间兼容性
parent
35ec27b7d7
commit
aa546ac692
|
@ -5,13 +5,17 @@ import random
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
saleMinDelayDay = 0
|
from myException.ticketConfigException import ticketConfigException
|
||||||
saleMaxDelayDay = 59
|
|
||||||
saleStartTime = "06:00:00"
|
|
||||||
saleStopTime = "23:00:00"
|
|
||||||
rushRefreshMinTimeIntval = 2000
|
rushRefreshMinTimeIntval = 2000
|
||||||
rushRefreshMaxTimeIntval = 3600000
|
rushRefreshMaxTimeIntval = 3600000
|
||||||
rushRefreshTimeIntval = 100
|
rushRefreshTimeIntval = 100
|
||||||
|
# 最早运行时间
|
||||||
|
maxRunTime = 7
|
||||||
|
# 程序停止时间
|
||||||
|
maxRunStopTime = 23
|
||||||
|
# 可售天数
|
||||||
|
maxDate = 29
|
||||||
|
|
||||||
RS_SUC = 0
|
RS_SUC = 0
|
||||||
RS_TIMEOUT = 1
|
RS_TIMEOUT = 1
|
||||||
|
@ -39,22 +43,6 @@ def getNowTimestamp():
|
||||||
return time.time()
|
return time.time()
|
||||||
|
|
||||||
|
|
||||||
def getMinimumDate():
|
|
||||||
return time.localtime(getNowTimestamp() + saleMinDelayDay * 24 * 3600)[:3]
|
|
||||||
|
|
||||||
|
|
||||||
def getMaximumDate():
|
|
||||||
return time.localtime(getNowTimestamp() + saleMaxDelayDay * 24 * 3600)[:3]
|
|
||||||
|
|
||||||
|
|
||||||
def getMinimumTime():
|
|
||||||
return [int(x) for x in saleStartTime.split(":")]
|
|
||||||
|
|
||||||
|
|
||||||
def getMaximumTime():
|
|
||||||
return [int(x) for x in saleStopTime.split(":")]
|
|
||||||
|
|
||||||
|
|
||||||
def decMakeDir(func):
|
def decMakeDir(func):
|
||||||
def handleFunc(*args, **kwargs):
|
def handleFunc(*args, **kwargs):
|
||||||
dirname = func(*args, **kwargs)
|
dirname = func(*args, **kwargs)
|
||||||
|
@ -117,10 +105,31 @@ def getCacheFile(cacheType):
|
||||||
|
|
||||||
def checkSleepTime(session):
|
def checkSleepTime(session):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
if now.hour >= 23 or now.hour < 7:
|
if now.hour >= maxRunStopTime or now.hour < maxRunTime:
|
||||||
print(u"12306休息时间,本程序自动停止,明天早上六点将自动运行")
|
print(u"12306休息时间,本程序自动停止,明天早上六点将自动运行")
|
||||||
open_time = datetime.datetime(now.year, now.month, now.day, 7)
|
open_time = datetime.datetime(now.year, now.month, now.day, 7)
|
||||||
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)))
|
||||||
session.call_login()
|
session.call_login()
|
||||||
|
|
||||||
|
|
||||||
|
def checkDate(station_dates):
|
||||||
|
"""
|
||||||
|
检查日期是否合法
|
||||||
|
:param station_dates:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
today = datetime.datetime.now()
|
||||||
|
maxDay = (today + datetime.timedelta(maxDate)).strftime("%Y-%m-%d")
|
||||||
|
for station_date in station_dates[::-1]:
|
||||||
|
date = datetime.datetime.strftime(datetime.datetime.strptime(station_date, "%Y-%m-%d"), "%Y-%m-%d")
|
||||||
|
if date < today.strftime("%Y-%m-%d") or date > maxDay:
|
||||||
|
print(u"警告:当前时间配置有小于当前时间或者大于最大时间: {}, 已自动忽略".format(station_date))
|
||||||
|
station_dates.remove(station_date)
|
||||||
|
if not station_dates:
|
||||||
|
print(u"当前日期设置无符合查询条件的,已被全部删除,请查证后添加!!!")
|
||||||
|
raise ticketConfigException(u"当前日期设置无符合查询条件的,已被全部删除,请查证后添加!!!")
|
||||||
|
else:
|
||||||
|
station_dates[station_dates.index(station_date)] = date
|
||||||
|
return station_dates
|
||||||
|
|
|
@ -12,8 +12,7 @@ import wrapcache
|
||||||
from agency.cdn_utils import CDNProxy
|
from agency.cdn_utils import CDNProxy
|
||||||
from config import urlConf, configCommon
|
from config import urlConf, configCommon
|
||||||
from config.TicketEnmu import ticket
|
from config.TicketEnmu import ticket
|
||||||
from config.configCommon import seat_conf
|
from config.configCommon import seat_conf, checkDate, seat_conf_2
|
||||||
from config.configCommon import seat_conf_2
|
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
from init.login import GoLogin
|
from init.login import GoLogin
|
||||||
from inter.AutoSubmitOrderRequest import autoSubmitOrderRequest
|
from inter.AutoSubmitOrderRequest import autoSubmitOrderRequest
|
||||||
|
@ -67,7 +66,8 @@ class select:
|
||||||
ticket_info_config = _get_yaml()
|
ticket_info_config = _get_yaml()
|
||||||
from_station = ticket_info_config["set"]["from_station"]
|
from_station = ticket_info_config["set"]["from_station"]
|
||||||
to_station = ticket_info_config["set"]["to_station"]
|
to_station = ticket_info_config["set"]["to_station"]
|
||||||
station_dates = ticket_info_config["set"]["station_dates"]
|
station_dates = checkDate(ticket_info_config["set"]["station_dates"])
|
||||||
|
|
||||||
set_names = ticket_info_config["set"]["set_type"]
|
set_names = ticket_info_config["set"]["set_type"]
|
||||||
try:
|
try:
|
||||||
set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]]
|
set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]]
|
||||||
|
|
|
@ -144,7 +144,7 @@ class query:
|
||||||
else:
|
else:
|
||||||
print(u"设置乘车人数为: {}".format(self.ticke_peoples_num))
|
print(u"设置乘车人数为: {}".format(self.ticke_peoples_num))
|
||||||
is_more_ticket_num = self.ticke_peoples_num
|
is_more_ticket_num = self.ticke_peoples_num
|
||||||
print (ticket.QUERY_C)
|
print(ticket.QUERY_C)
|
||||||
return {
|
return {
|
||||||
"secretStr": secretStr,
|
"secretStr": secretStr,
|
||||||
"train_no": train_no,
|
"train_no": train_no,
|
||||||
|
|
Loading…
Reference in New Issue