From aa546ac692cc9348affaf5c8e192c16a093b0446 Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Thu, 24 Jan 2019 17:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/configCommon.py | 51 ++++++++++++++++++++++---------------- init/select_ticket_info.py | 6 ++--- inter/Query.py | 2 +- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/config/configCommon.py b/config/configCommon.py index 73cd2d3..81f53e7 100755 --- a/config/configCommon.py +++ b/config/configCommon.py @@ -5,13 +5,17 @@ import random import sys import time -saleMinDelayDay = 0 -saleMaxDelayDay = 59 -saleStartTime = "06:00:00" -saleStopTime = "23:00:00" +from myException.ticketConfigException import ticketConfigException + rushRefreshMinTimeIntval = 2000 rushRefreshMaxTimeIntval = 3600000 rushRefreshTimeIntval = 100 +# 最早运行时间 +maxRunTime = 7 +# 程序停止时间 +maxRunStopTime = 23 +# 可售天数 +maxDate = 29 RS_SUC = 0 RS_TIMEOUT = 1 @@ -39,22 +43,6 @@ def getNowTimestamp(): 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 handleFunc(*args, **kwargs): dirname = func(*args, **kwargs) @@ -117,10 +105,31 @@ def getCacheFile(cacheType): def checkSleepTime(session): now = datetime.datetime.now() - if now.hour >= 23 or now.hour < 7: + if now.hour >= maxRunStopTime or now.hour < maxRunTime: print(u"12306休息时间,本程序自动停止,明天早上六点将自动运行") open_time = datetime.datetime(now.year, now.month, now.day, 7) if open_time < now: open_time += datetime.timedelta(1) time.sleep((open_time - now).seconds + round(random.uniform(1, 10))) 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 diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index b4afa6f..3a53cdc 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -12,8 +12,7 @@ import wrapcache from agency.cdn_utils import CDNProxy from config import urlConf, configCommon from config.TicketEnmu import ticket -from config.configCommon import seat_conf -from config.configCommon import seat_conf_2 +from config.configCommon import seat_conf, checkDate, seat_conf_2 from config.ticketConf import _get_yaml from init.login import GoLogin from inter.AutoSubmitOrderRequest import autoSubmitOrderRequest @@ -67,7 +66,8 @@ class select: ticket_info_config = _get_yaml() from_station = ticket_info_config["set"]["from_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"] try: set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]] diff --git a/inter/Query.py b/inter/Query.py index 01f7baf..e3ead7b 100644 --- a/inter/Query.py +++ b/inter/Query.py @@ -144,7 +144,7 @@ class query: else: print(u"设置乘车人数为: {}".format(self.ticke_peoples_num)) is_more_ticket_num = self.ticke_peoples_num - print (ticket.QUERY_C) + print(ticket.QUERY_C) return { "secretStr": secretStr, "train_no": train_no, -- GitLab