mirror of https://github.com/testerSunshine/12306
parent
ac1a03834e
commit
fb92dbaece
12
README.md
12
README.md
|
@ -74,3 +74,15 @@
|
|||
- 2018.1.12更新
|
||||
- 优化抢票页面逻辑
|
||||
-增强代码稳定性
|
||||
|
||||
- 2018.1.13更新
|
||||
- 修改下单验证码功能
|
||||
- 增加邮箱功能
|
||||
```
|
||||
#is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定要到config目录下测试emailConf功能是否正常
|
||||
#email: 发送的邮箱地址 ex: 1@qq.com
|
||||
#notice_email_list: 被通知人邮箱 ex: 2@qq.com
|
||||
#username: 邮箱账号
|
||||
#password: 邮箱密码
|
||||
#host: 邮箱地址
|
||||
```
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf8 -*-
|
||||
__author__ = 'MR.wen'
|
||||
from email.header import Header
|
||||
from email.mime.text import MIMEText
|
||||
from config.ticketConf import _get_yaml
|
||||
import smtplib
|
||||
|
||||
|
||||
def sendEmail(msg):
|
||||
"""
|
||||
邮件通知
|
||||
:param str: email content
|
||||
:return:
|
||||
"""
|
||||
email_conf = _get_yaml()
|
||||
is_email = email_conf["email_conf"]["is_email"]
|
||||
if is_email:
|
||||
sender = email_conf["email_conf"]["email"]
|
||||
receiver = email_conf["email_conf"]["notice_email_list"]
|
||||
subject = '恭喜,您已订票成功'
|
||||
username = email_conf["email_conf"]["username"]
|
||||
password = email_conf["email_conf"]["password"]
|
||||
host = email_conf["email_conf"]["host"]
|
||||
s = "{0}".format(msg)
|
||||
|
||||
msg = MIMEText(s, 'text', 'utf-8') # 中文需参数‘utf-8’,单字节字符不需要
|
||||
msg['Subject'] = Header(subject, 'utf-8')
|
||||
msg['From'] = sender
|
||||
msg['To'] = receiver
|
||||
|
||||
smtp = smtplib.SMTP()
|
||||
smtp.connect(host)
|
||||
smtp.login(username, password)
|
||||
smtp.sendmail(sender, receiver.split(","), msg.as_string())
|
||||
smtp.quit()
|
||||
print("邮件已通知, 请查收")
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sendEmail(1)
|
|
@ -22,34 +22,40 @@
|
|||
#ticke_peoples: 乘客
|
||||
#damatu:打码兔账号,用于自动登录
|
||||
#is_aotu_code是否自动打码,如果选择Ture,则调用打码兔打码,默认不使用打码兔
|
||||
#is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定要到config目录下测试emailConf功能是否正常
|
||||
#email: 发送的邮箱地址 ex: 1@qq.com
|
||||
#notice_email_list: 被通知人邮箱 ex: 2@qq.com
|
||||
#username: 邮箱账号
|
||||
#password: 邮箱密码
|
||||
#host: 邮箱地址
|
||||
|
||||
|
||||
set:
|
||||
station_date: "2018-02-10"
|
||||
station_date: "2018-02-07"
|
||||
station_trains:
|
||||
- "T17"
|
||||
- "T297"
|
||||
# - "G2365"
|
||||
# - "G1371"
|
||||
# - "G1377"
|
||||
# - "G1329"
|
||||
# - "G1305"
|
||||
- "G4741"
|
||||
- "G2365"
|
||||
- "G1371"
|
||||
- "G1377"
|
||||
- "G4933"
|
||||
# - "G1359"
|
||||
# - "G1361"
|
||||
# - "G1373"
|
||||
# - "G1363"
|
||||
# - "G4933"
|
||||
from_station: "北京"
|
||||
to_station: "牡丹江"
|
||||
from_station: "上海"
|
||||
to_station: "长沙"
|
||||
set_type:
|
||||
- "硬卧"
|
||||
- "一等座"
|
||||
is_more_ticket: True
|
||||
ticke_peoples:
|
||||
- ""
|
||||
- ""
|
||||
- "宋倩倩"
|
||||
# - "彭淑杰"
|
||||
12306count:
|
||||
# - uesr: ""
|
||||
# - pwd: "649823049lilymin"
|
||||
- uesr: "@qq.com"
|
||||
- pwd: "QWERTY"
|
||||
# - pwd: "apple1995"
|
||||
- uesr: ""
|
||||
- pwd: "songyu1995"
|
||||
|
||||
select_refresh_interval: 0.1
|
||||
expect_refresh_interval: 0.3
|
||||
|
@ -61,5 +67,14 @@ damatu:
|
|||
uesr: ""
|
||||
pwd: "wen1995"
|
||||
|
||||
email_conf:
|
||||
is_email: True
|
||||
email: ""
|
||||
notice_email_list: ""
|
||||
username: ".wen"
|
||||
password: "!"
|
||||
host: "mail..com"
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import sys
|
|||
import time
|
||||
from collections import OrderedDict
|
||||
|
||||
from config.emailConf import sendEmail
|
||||
from config.ticketConf import _get_yaml
|
||||
from damatuCode.damatuWeb import DamatuApi
|
||||
from myException.PassengerUserException import PassengerUserException
|
||||
|
@ -457,7 +458,7 @@ class select:
|
|||
if is_node_code:
|
||||
print("正在使用自动识别验证码功能")
|
||||
randurl = 'https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn'
|
||||
codeimg = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=sjrand&%s' % random.random()
|
||||
codeimg = 'https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&%s' % random.random()
|
||||
result = myurllib2.get(codeimg)
|
||||
img_path = './tkcode'
|
||||
open(img_path, 'wb').write(result)
|
||||
|
@ -471,16 +472,16 @@ class select:
|
|||
}
|
||||
fresult = json.loads(myurllib2.Post(randurl, randData), encoding='utf8') # 校验验证码是否正确
|
||||
checkcode = fresult['data']['msg']
|
||||
if checkcode == 'FALSE':
|
||||
print ("验证码有误,第{}次尝试重试".format(i))
|
||||
else:
|
||||
if checkcode == 'TRUE':
|
||||
print("验证码通过,正在提交订单")
|
||||
data['randCode'] = randCode
|
||||
break
|
||||
else:
|
||||
print ("验证码有误, 接口返回{0} 第{1}次尝试重试".format(fresult, i))
|
||||
else:
|
||||
print("不需要验证码")
|
||||
break
|
||||
print("".join(data))
|
||||
# print("".join(data))
|
||||
checkQueueOrderResult = json.loads(myurllib2.Post(checkQueueOrderUrl, data))
|
||||
if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]:
|
||||
c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {}
|
||||
|
@ -526,6 +527,7 @@ class select:
|
|||
if queryOrderWaitTimeResult:
|
||||
if "status" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["status"]:
|
||||
if "orderId" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["orderId"] is not None:
|
||||
sendEmail("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"]))
|
||||
raise ticketIsExitsException("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"]))
|
||||
elif "msg" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["msg"]:
|
||||
print queryOrderWaitTimeResult["data"]["msg"]
|
||||
|
@ -540,10 +542,12 @@ class select:
|
|||
print("第{}次排队中,请耐心等待".format(num))
|
||||
else:
|
||||
print("排队中")
|
||||
time.sleep(2)
|
||||
time.sleep(1)
|
||||
order_id = self.queryMyOrderNoComplete() # 尝试查看订单列表,如果有订单,则判断成功,不过一般可能性不大
|
||||
if order_id:
|
||||
sendEmail("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(order_id))
|
||||
raise ticketIsExitsException("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(order_id))
|
||||
|
||||
else:
|
||||
print(ticketNumOutException("订单提交失败!,正在重新刷票"))
|
||||
|
||||
|
|
Loading…
Reference in New Issue