From da1a0903c53f4e8b116a487d00061e1e633d84b4 Mon Sep 17 00:00:00 2001 From: IronXiao Date: Mon, 6 Jan 2020 15:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BD=BF=E7=94=A8=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E7=BC=93=E5=AD=98RAIL=5FEXPIRATION=20?= =?UTF-8?q?=E5=92=8C=20RAIL=5FDEVICEID=20=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=B4=E6=97=B6=E6=97=A0=E6=B3=95=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env.py.example | 5 +++++ py12306/config.py | 8 ++++++++ py12306/user/job.py | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/env.py.example b/env.py.example index 834460d..4887eed 100644 --- a/env.py.example +++ b/env.py.example @@ -109,6 +109,11 @@ WEB_PORT = 8008 # 监听端口 CDN_ENABLED = 0 CDN_CHECK_TIME_OUT = 1 # 检测单个 cdn 是否可用超时时间 +# 是否使用浏览器缓存中的RAIL_EXPIRATION 和 RAIL_DEVICEID +CACHE_RAIL_ID_ENABLED = 0 +RAIL_EXPIRATION = '' #浏览12306 网站中的Cache的RAIL_EXPIRATION 值 +RAIL_DEVICEID = '' #浏览12306 网站中的Cache的RAIL_DEVICEID 值 + # 查询任务 QUERY_JOBS = [ { diff --git a/py12306/config.py b/py12306/config.py index e1b203f..9944832 100644 --- a/py12306/config.py +++ b/py12306/config.py @@ -94,6 +94,10 @@ class Config: CDN_ITEM_FILE = PROJECT_DIR + 'data/cdn.txt' CDN_ENABLED_AVAILABLE_ITEM_FILE = QUERY_DATA_DIR + 'available.json' + CACHE_RAIL_ID_ENABLED = 0 + RAIL_EXPIRATION = '' + RAIL_DEVICEID = '' + # Default time out TIME_OUT_OF_REQUEST = 5 @@ -213,6 +217,10 @@ class Config: def is_cdn_enabled(): return Config().CDN_ENABLED + @staticmethod + def is_cache_rail_id_enabled(): + return Config().CACHE_RAIL_ID_ENABLED + class EnvLoader: envs = [] diff --git a/py12306/user/job.py b/py12306/user/job.py index 1d0f5c1..459690c 100644 --- a/py12306/user/job.py +++ b/py12306/user/job.py @@ -197,10 +197,16 @@ class UserJob: if response.text.find('callbackFunction') >= 0: result = response.text[18:-2] result = json.loads(result) - self.session.cookies.update({ - 'RAIL_EXPIRATION': result.get('exp'), - 'RAIL_DEVICEID': result.get('dfp'), - }) + if not Config().is_cache_rail_id_enabled(): + self.session.cookies.update({ + 'RAIL_EXPIRATION': result.get('exp'), + 'RAIL_DEVICEID': result.get('dfp'), + }) + else: + self.session.cookies.update({ + 'RAIL_EXPIRATION': Config().RAIL_EXPIRATION, + 'RAIL_DEVICEID': Config().RAIL_DEVICEID, + }) except: return False