From 95e9e8a89b738647293bba93ffd08deedf92dd18 Mon Sep 17 00:00:00 2001 From: out0fmemory Date: Fri, 27 Dec 2019 18:43:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=88=B02020=E5=B9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.py.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/env.py.example b/env.py.example index 72be784..834460d 100644 --- a/env.py.example +++ b/env.py.example @@ -115,8 +115,8 @@ QUERY_JOBS = [ # 'job_name': 'bj -> sz', # 任务名称,不填默认会以车站名命名,不可重复 'account_key': 0, # 将会使用指定账号下单 'left_dates': [ # 出发日期 :Array - "2019-01-25", - "2019-01-26", + "2020-01-25", + "2020-01-26", ], 'stations': { # 车站 支持多个车站同时查询 :Dict or :List 'left': '北京', From eee53461cf885105533a1e439d18163b7c6a1f5a Mon Sep 17 00:00:00 2001 From: out0fmemory Date: Fri, 27 Dec 2019 18:44:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B9=B0=E7=A5=A8?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=87=BA=E7=8E=B0=E6=97=A5=E6=9C=9F=E4=B8=8D?= =?UTF-8?q?=E5=AF=B9=EF=BC=8C=E4=BD=86=E6=98=AF=E6=8A=A5=E7=9A=84=E6=98=AF?= =?UTF-8?q?302=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py12306/query/job.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/py12306/query/job.py b/py12306/query/job.py index cc1a374..8b91c45 100644 --- a/py12306/query/job.py +++ b/py12306/query/job.py @@ -1,5 +1,6 @@ import sys from datetime import timedelta +from datetime import datetime from py12306.app import app_available_check from py12306.cluster.cluster import Cluster @@ -66,6 +67,8 @@ class Job: INDEX_LEFT_TIME = 8 INDEX_ARRIVE_TIME = 9 + max_buy_time = 32 + def __init__(self, info, query): self.cluster = Cluster() self.query = query @@ -136,11 +139,29 @@ class Job: QueryLog.add_log('\n').flush(sep='\t\t', publish=False) if Const.IS_TEST: return + def judge_date_legal(self, date): + date_now = datetime.datetime.now() + date_query = datetime.datetime.strptime(str(date), "%Y-%m-%d") + diff = (date_query - date_now).days + if date_now.day == date_query.day: + diff = 0 + if diff < 0: + msg = '乘车日期错误,比当前时间还早!!' + QueryLog.add_quick_log(msg).flush(publish=False) + raise RuntimeError(msg) + elif diff > self.max_buy_time: + msg = '乘车日期错误,超出一个月预售期!!' + QueryLog.add_quick_log(msg).flush(publish=False) + raise RuntimeError(msg) + else: + pass + def query_by_date(self, date): """ 通过日期进行查询 :return: """ + self.judge_date_legal(date) from py12306.helpers.cdn import Cdn QueryLog.add_log(('\n' if not is_main_thread() else '') + QueryLog.MESSAGE_QUERY_START_BY_DATE.format(date, self.left_station,