Skip to content

Commit 808c302

Browse files
author
文贤平
committed
新增候补功能
1 parent c5c9450 commit 808c302

25 files changed

Lines changed: 587 additions & 466 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.log
55
.idea/
66
*.h5
7+
tkcode.png

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
- 非root用户(避免安装和运行时使用了不同环境): `pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt`
1919
2020
#### 项目使用说明
21-
- 可以配置邮箱,可以配置可以不配置,配置邮箱的格式在[yaml](config/ticket_config.yaml)里面可以看到ex
21+
- 可以配置邮箱,可以配置可以不配置,配置邮箱的格式在[配置](TickerConfig.py)里面可以看到ex
2222
- 可以配置server酱提醒(推荐), [配置教程](https://www.jianshu.com/p/8d10b5b9c4e3)
23-
- 配置[yaml](config/ticket_config.yaml)文件的时候,需注意空格和遵循yaml语法格式
23+
- 配置[配置](TickerConfig.py)文件的时候,需注意空格和遵循yaml语法格式
2424
2525
#### 项目开始
2626
- 服务器启动:
27-
- 修改[config/ticket_config.yaml](config/ticket_config.yaml)文件,按照提示更改自己想要的信息
27+
- 修改[配置](TickerConfig.py)文件,按照提示更改自己想要的信息
2828
- 运行根目录`sudo python run.py`,即可开始
2929
- 由于新增对时功能,请务必用**sudo,sudo,sudo** 执行,否则会报权限错误,windows打开ide或者cmd请用管理员身份执行`python run.py`,不需要加`sudo`
3030
- 如果你的服务器安装了docker与docker-compose, 那么就可以通过`docker-compose`进行启动,`docker.sh`脚本对此进行了封装,可以通过如下命令进行启动

TickerConfig.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# 刷票模式:1=刷票 2=候补
2+
TICKET_TYPE = 2
3+
4+
# 候补最晚兑现日期,如果是候补订单,这个值一定要填
5+
# 格式为日期+小时+分
6+
# t("#fromDate").val() + "#" + t("#dafaultTime").html().replace("时", "") + "#" + t("#dafaultMinutes").html().replace("分", ""),
7+
J_Z_PARAM = "2019-09-10#22#59"
8+
9+
# 出发日期(list) "2018-01-06", "2018-01-07"
10+
STATION_DATES = [
11+
"2019-09-30"
12+
]
13+
14+
# 填入需要购买的车次(list),"G1353"
15+
STATION_TRAINS = [
16+
"G1377"
17+
]
18+
19+
# 出发城市,比如深圳北,就填深圳就搜得到
20+
FROM_STATION = "上海"
21+
22+
# 到达城市 比如深圳北,就填深圳就搜得到
23+
TO_STATION = "长沙"
24+
25+
# 座位(list) 多个座位ex:
26+
# - "商务座"
27+
# - "一等座"
28+
# - "二等座"
29+
# - "特等座"
30+
# - "软卧"
31+
# - "硬卧"
32+
# - "硬座"
33+
# - "无座"
34+
# - "动卧"
35+
SET_TYPE = [
36+
"二等座"
37+
]
38+
39+
# 当余票小于乘车人,如果选择优先提交,则删减联系人和余票数一致在提交
40+
# bool
41+
IS_MORE_TICKET = False
42+
43+
# 乘车人(list) 多个乘车人ex:
44+
# - "张三"
45+
# - "李四"
46+
TICKET_PEOPLES = [
47+
""
48+
]
49+
50+
# 12306登录账号
51+
USER = ""
52+
PWD = ""
53+
54+
# 加入小黑屋时间默认为5分钟,此功能为了防止僵尸票导致一直下单不成功错过正常的票
55+
TICKET_BLACK_LIST_TIME = 5
56+
57+
# 自动打码
58+
IS_AUTO_CODE = True
59+
60+
# 邮箱配置,如果抢票成功,将通过邮件配置通知给您
61+
# 列举163
62+
# email: "xxx@163.com"
63+
# notice_email_list: "123@qq.com"
64+
# username: "xxxxx"
65+
# password: "xxxxx
66+
# host: "smtp.163.com"
67+
# 列举qq ,qq设置比较复杂,需要在邮箱-->账户-->开启smtp服务,取得授权码==邮箱登录密码
68+
# email: "xxx@qq.com"
69+
# notice_email_list: "123@qq.com"
70+
# username: "xxxxx"
71+
# password: "授权码"
72+
# host: "smtp.qq.com"
73+
EMAIL_CONF = {
74+
"IS_MAIL": True,
75+
"email": "",
76+
"notice_email_list": "",
77+
"username": "",
78+
"password": "",
79+
"host": "",
80+
}
81+
82+
# 是否开启 pushbear 微信提醒, 使用前需要前往 http://pushbear.ftqq.com 扫码绑定获取 send_key 并关注获得抢票结果通知的公众号
83+
PUSHBEAR_CONF = {
84+
"is_pushbear": False,
85+
"send_key": ""
86+
}
87+
88+
# 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭
89+
IS_CDN = 1
90+
91+
# 下单接口分为两种,1 模拟网页自动捡漏下单(不稳定),2 模拟车次后面的购票按钮下单(稳如老狗)
92+
ORDER_TYPE = 2
93+
94+
# 下单模式 1 为预售,整点刷新,刷新间隔0.1-0.5S, 然后会校验时间,比如12点的预售,那脚本就会在12.00整检票,刷新订单
95+
# 2 是捡漏,捡漏的刷新间隔时间为0.5-3秒,时间间隔长,不容易封ip
96+
ORDER_MODEL = 2
97+
98+
# 是否开启代理, 0代表关闭, 1表示开始
99+
# 开启此功能的时候请确保代理ip是否可用,在测试放里面经过充分的测试,再开启此功能,不然可能会耽误你购票的宝贵时间
100+
# 使用方法:
101+
# 1、在agency/proxy_list列表下填入代理ip
102+
# 2、测试UnitTest/TestAll/testProxy 测试代理是否可以用
103+
# 3、开启代理ip
104+
IS_PROXY = 0
105+
106+
# 预售放票时间, 如果是捡漏模式,可以忽略此操作
107+
OPEN_TIME = "13:00:00"
108+
109+
PASSENGER_TICKER_STR = {
110+
'一等座': 'M',
111+
'特等座': 'P',
112+
'二等座': 'O',
113+
'商务座': 9,
114+
'硬座': 1,
115+
'无座': 1,
116+
'软座': 2,
117+
'软卧': 4,
118+
'硬卧': 3,
119+
}

UnitTest/TestAll.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ def testPushbear(self):
5353
# :return:
5454
# """
5555

56-
5756
if __name__ == '__main__':
5857
unittest.main()

Update.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@
157157
- 删除若快打码
158158
- 修复不能下单问题
159159
- 放弃支持python2.7,只支持3.6以上版本
160+
161+
- 2019.09.01更新
162+
- 去除yaml配置文件,改为py文件配置
163+
- 增加候补订单功能
164+
- 新增TICKET_TYPE字段,1=刷票 2=候补
165+
- 目前候补只支持单车次,多乘车人候补,由于目前不是很懂候补的需求,所以暂时这样做

config/TicketEnmu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# coding=utf-8
2+
from enum import Enum
23

34

45
class ticket(object):
@@ -25,6 +26,7 @@ class ticket(object):
2526
OUT_NUM = 120 # 排队请求12306的次数
2627
WAIT_OUT_NUM = u"超出排队时间,自动放弃,正在重新刷票"
2728
WAIT_ORDER_SUCCESS = u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!"
29+
WAIT_AFTER_NATE_SUCCESS = u"候补订单已完成,请立即打开浏览器登录12306,访问‘候补订单’,在30分钟内完成支付!"
2830
WAIT_ORDER_CONTINUE = u"排队等待时间预计还剩 {0} ms"
2931
WAIT_ORDER_FAIL = u"排队等待失败,错误消息:{0}"
3032
WAIT_ORDER_NUM = u"第{0}次排队中,请耐心等待"
@@ -37,4 +39,3 @@ class ticket(object):
3739
REST_TIME_PAST = u"休息时间已过,重新开启检票功能"
3840

3941
LOGIN_SESSION_FAIL = u"用户检查失败:{0},可能未登录,可能session已经失效, 正在重新登录中"
40-

config/emailConf.py

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# -*- coding: utf8 -*-
22
import socket
3-
43
__author__ = 'MR.wen'
4+
import TickerConfig
55
from email.header import Header
66
from email.mime.text import MIMEText
7-
from config.ticketConf import _get_yaml
87
import smtplib
98

109

@@ -14,38 +13,33 @@ def sendEmail(msg):
1413
:param str: email content
1514
:return:
1615
"""
17-
email_conf = _get_yaml()
18-
is_email = email_conf["email_conf"]["is_email"]
19-
if is_email:
20-
try:
21-
sender = email_conf["email_conf"]["email"]
22-
receiver = email_conf["email_conf"]["notice_email_list"]
23-
subject = '恭喜,您已订票成功'
24-
username = email_conf["email_conf"]["username"]
25-
password = email_conf["email_conf"]["password"]
26-
host = email_conf["email_conf"]["host"]
27-
s = "{0}".format(msg)
16+
try:
17+
sender = TickerConfig.EMAIL_CONF["email"]
18+
receiver = TickerConfig.EMAIL_CONF["notice_email_list"]
19+
subject = '恭喜,您已订票成功'
20+
username = TickerConfig.EMAIL_CONF["username"]
21+
password = TickerConfig.EMAIL_CONF["password"]
22+
host = TickerConfig.EMAIL_CONF["host"]
23+
s = "{0}".format(msg)
2824

29-
msg = MIMEText(s, 'plain', 'utf-8') # 中文需参数‘utf-8’,单字节字符不需要
30-
msg['Subject'] = Header(subject, 'utf-8')
31-
msg['From'] = sender
32-
msg['To'] = receiver
25+
msg = MIMEText(s, 'plain', 'utf-8') # 中文需参数‘utf-8’,单字节字符不需要
26+
msg['Subject'] = Header(subject, 'utf-8')
27+
msg['From'] = sender
28+
msg['To'] = receiver
3329

34-
try:
35-
smtp = smtplib.SMTP_SSL()
36-
smtp.connect(host)
37-
except socket.error:
38-
smtp = smtplib.SMTP()
39-
smtp.connect(host)
30+
try:
31+
smtp = smtplib.SMTP_SSL()
32+
smtp.connect(host)
33+
except socket.error:
34+
smtp = smtplib.SMTP()
4035
smtp.connect(host)
41-
smtp.login(username, password)
42-
smtp.sendmail(sender, receiver.split(","), msg.as_string())
43-
smtp.quit()
44-
print(u"邮件已通知, 请查收")
45-
except Exception as e:
46-
print(u"邮件配置有误{}".format(e))
47-
else:
48-
pass
36+
smtp.connect(host)
37+
smtp.login(username, password)
38+
smtp.sendmail(sender, receiver.split(","), msg.as_string())
39+
smtp.quit()
40+
print(u"邮件已通知, 请查收")
41+
except Exception as e:
42+
print(u"邮件配置有误{}".format(e))
4943

5044

5145
if __name__ == '__main__':

config/pushbearConf.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf8 -*-
2-
import time
3-
4-
import requests
5-
from config.ticketConf import _get_yaml
2+
import TickerConfig
63
from config.urlConf import urls
74
from myUrllib.httpUtils import HTTPClient
85

@@ -15,12 +12,11 @@ def sendPushBear(msg):
1512
:param str: 通知内容 content
1613
:return:
1714
"""
18-
conf = _get_yaml()
19-
if conf["pushbear_conf"]["is_pushbear"] and conf["pushbear_conf"]["send_key"].strip() != "":
15+
if TickerConfig.PUSHBEAR_CONF["is_pushbear"] and TickerConfig.PUSHBEAR_CONF["pushbear_conf"]["send_key"].strip() != "":
2016
try:
2117
sendPushBearUrls = urls.get("Pushbear")
2218
data = {
23-
"sendkey": conf["pushbear_conf"]["send_key"].strip(),
19+
"sendkey": TickerConfig.PUSHBEAR_CONF["pushbear_conf"]["send_key"].strip(),
2420
"text": "易行购票成功通知",
2521
"desp": msg
2622
}

config/ticketConf.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)