Skip to content

Commit

Permalink
修改休眠bug
Browse files Browse the repository at this point in the history
增加软卧功能
  • Loading branch information
testerSunshine committed Jan 6, 2019
1 parent fb03acd commit cfebf48
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
14 changes: 13 additions & 1 deletion config/configCommon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import datetime
import os
import sys
import time
Expand All @@ -23,6 +23,7 @@
'特等座': 25,
'软卧': 23,
'硬卧': 28,
'软座': 24,
'硬座': 29,
'无座': 26,
}
Expand Down Expand Up @@ -95,3 +96,14 @@ def getVCodeImageFile(imageName):

def getCacheFile(cacheType):
return os.path.join(getCacheDir(), cacheType + ".cache")


def checkSleepTime(session):
now = datetime.datetime.now()
if now.hour >= 23 or now.hour < 6:
print(u"12306休息时间,本程序自动停止,明天早上七点将自动运行")
open_time = datetime.datetime(now.year, now.month, now.day, 6)
if open_time < now:
open_time += datetime.timedelta(1)
time.sleep((open_time - now).seconds)
session.call_login()
24 changes: 14 additions & 10 deletions config/ticket_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set:
# - 2018-01-06
# - 2018-01-07
station_dates:
- "2019-01-11"
- "2019-02-02"

# 是否根据时间范围 和 乘车类型 购票
# 否则将需要手动填写车次
Expand Down Expand Up @@ -45,15 +45,18 @@ set:
# - "G1021"
# - "G99"
# - "G6011"
- "D2972"
- "D1874"
- "D2834"
# - "D2972"
# - "D1874"
# - "D2834"
- "G6172"
- "G6186"
- "G6154"

# 出发城市,比如深圳北,就填深圳就搜得到
from_station: "广州南"

# 到达城市 比如深圳北,就填深圳就搜得到
to_station: "三江南"
to_station: "邵阳"

# 座位(list) 多个座位ex:
# - "二等座"
Expand All @@ -68,8 +71,9 @@ set:
# - "张三"
# - "李四"
ticke_peoples:
# - "文贤平"
- "梁敏"
- "文贤平"
- "李梦云"
# - "梁敏"
# 12306登录账号(list)
12306account:
- user: "[email protected]"
Expand All @@ -79,7 +83,7 @@ set:
ticket_black_list_time: 5

# 自动打码
is_auto_code: True
is_auto_code: False

# 打码平台, 2 为若快平台(目前只支持若快平台打码,打码兔已经关闭), 若快注册地址:http://www.ruokuai.com/client/index?6726
auto_code_type: 2
Expand Down Expand Up @@ -114,14 +118,14 @@ email_conf:
is_cdn: 1

# 下单接口分为两种,1 为快速下单,2 是普通下单
order_type: 1
order_type: 2

# 下单模式 1 为预售,整点刷新,刷新间隔0.1-0.5S, 然后会校验时间,比如12点的预售,那脚本就会在12.00整检票,刷新订单
# 2 是捡漏,捡漏的刷新间隔时间为0.5-3秒,时间间隔长,不容易封ip
order_model: 2

# 预售放票时间, 如果是捡漏模式,可以忽略此操作
open_time: '20:15:00'
open_time: '13:00:00'



10 changes: 2 additions & 8 deletions init/select_ticket_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import wrapcache

from agency.cdn_utils import CDNProxy
from config import urlConf
from config import urlConf, configCommon
from config.AutoSynchroTime import autoSynchroTime
from config.TicketEnmu import ticket
from config.configCommon import seat_conf
Expand Down Expand Up @@ -190,13 +190,7 @@ def main(self):
try:
num += 1
now = datetime.datetime.now() # 感谢群里大佬提供整点代码
if now.hour >= 23 or now.hour < 6:
print(u"12306休息时间,本程序自动停止,明天早上七点将自动运行")
open_time = datetime.datetime(now.year, now.month, now.day, 6)
if open_time < now:
open_time += datetime.timedelta(1)
time.sleep((open_time - now).seconds)
self.call_login()
configCommon.checkSleepTime(self) # 晚上到点休眠
if self.order_model is 1:
sleep_time_s = 0.5
sleep_time_t = 0.6
Expand Down
2 changes: 2 additions & 0 deletions inter/CheckUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import wrapcache

from config import configCommon
from config.TicketEnmu import ticket


Expand All @@ -16,6 +17,7 @@ def sendCheckUser(self):
"""
CHENK_TIME = 0.3
while 1:
configCommon.checkSleepTime(self.session) # 修复晚上查询线程休眠时,检查登录线程为休眠,造成快豆迅速消耗
if wrapcache.get("user_time") is None:
check_user_url = self.session.urls["check_user_url"]
data = {"_json_att": ""}
Expand Down
1 change: 1 addition & 0 deletions inter/GetPassengerDTOs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def getPassengerTicketStr(self, set_type):
'商务座': 9,
'硬座': 1,
'无座': 1,
'软座': 2,
'软卧': 4,
'硬卧': 3,
}
Expand Down

0 comments on commit cfebf48

Please sign in to comment.