mirror of https://github.com/testerSunshine/12306
parent
004b82831d
commit
bd1a0fcaa3
|
@ -1,15 +1,11 @@
|
|||
# encoding=utf8
|
||||
import collections
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
import csv
|
||||
import requests
|
||||
|
||||
from config import urlConf
|
||||
from myUrllib.httpUtils import HTTPClient
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
|
@ -88,7 +84,7 @@ class CDNProxy:
|
|||
num += 1
|
||||
except Exception as e:
|
||||
print(e.message)
|
||||
print("本次cdn获取完成,总个数{0}".format(num))
|
||||
print(u"本次cdn获取完成,总个数{0}".format(num))
|
||||
|
||||
def all_cdn(self):
|
||||
"""获取cdn列表"""
|
||||
|
@ -96,21 +92,17 @@ class CDNProxy:
|
|||
cdn = f.readlines()
|
||||
return cdn
|
||||
|
||||
def cdn_par(self):
|
||||
with open('./cdn_list', 'r') as f:
|
||||
cdn = f.readlines()
|
||||
print cdn
|
||||
for i in cdn:
|
||||
http = HTTPClient()
|
||||
check_user_url = self.urlConf["loginInit"]
|
||||
http.cdn = i.replace("\n", "")
|
||||
start_time = datetime.datetime.now()
|
||||
http.send(check_user_url)
|
||||
print (datetime.datetime.now() - start_time).microseconds / 1000
|
||||
def par_csv(self):
|
||||
cdn_csv = csv.reader(open("../cdn1.csv", "r"))
|
||||
for c in cdn_csv:
|
||||
cdn_re = re.compile(r'https://(\S+)/otn/index/init')
|
||||
cdn_ip = re.findall(cdn_re, c[0])
|
||||
if cdn_ip and c[2] == "200":
|
||||
print(cdn_ip[0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cdn = CDNProxy("kyfw.12306.cn")
|
||||
cdn = CDNProxy()
|
||||
cdn.get_city_id()
|
||||
# cdn.get_cdn_list()
|
||||
cdn.cdn_par()
|
||||
cdn.par_csv()
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#is_aotu_code是否自动打码,如果选择Ture,则调用打码兔打码,默认不使用打码兔
|
||||
#aotu_code_type 1为打码兔,2为若快
|
||||
#is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定到config目录下测试emailConf功能是否正常
|
||||
#is_cdn: 1为需要,2位本机ip查询
|
||||
|
||||
#邮箱配置 列举163
|
||||
# email: "xxx@163.com"
|
||||
|
@ -41,29 +42,17 @@
|
|||
|
||||
set:
|
||||
station_dates:
|
||||
# - "2018-01-27"
|
||||
# - "2018-01-28"
|
||||
# - "2018-02-22"
|
||||
- "2018-02-24"
|
||||
- "2018-02-02"
|
||||
station_trains:
|
||||
- "D2879"
|
||||
- "G2366"
|
||||
- "D1813"
|
||||
- "D2975"
|
||||
- "D1825"
|
||||
- "D1829"
|
||||
- "D2841"
|
||||
- "D1833"
|
||||
# - "K4300"
|
||||
# - "K5226"
|
||||
# - "K7772"
|
||||
# - "G1329"
|
||||
# - "G1359"
|
||||
# - "G1361"
|
||||
# - "G1373"
|
||||
# - "G1363"
|
||||
# - "G4933"
|
||||
from_station: "三江南"
|
||||
to_station: "广州南"
|
||||
from_station: "邵阳"
|
||||
to_station: "上海"
|
||||
set_type:
|
||||
- "一等座"
|
||||
- "二等座"
|
||||
|
@ -74,7 +63,7 @@ set:
|
|||
12306count:
|
||||
# - uesr: ""
|
||||
# - pwd: "apple1995"
|
||||
- uesr: "931128603@qq.com"
|
||||
- uesr: "@qq.com"
|
||||
- pwd: "QWERTY"
|
||||
|
||||
select_refresh_interval: 0.4
|
||||
|
@ -84,14 +73,14 @@ aotu_code_type: 2
|
|||
#enable_proxy: False
|
||||
|
||||
damatu:
|
||||
uesr: "931128603"
|
||||
uesr: ""
|
||||
pwd: "qazWSX1995"
|
||||
|
||||
email_conf:
|
||||
is_email: True
|
||||
email: "931128603@qq.com "
|
||||
email: "@qq.com "
|
||||
notice_email_list: "61995120@qq.com"
|
||||
username: "931128603"
|
||||
username: ""
|
||||
password: "xwopwxbkupbqbfgb"
|
||||
host: "smtp.qq.com"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ urls = {
|
|||
"auth": {
|
||||
"req_url": "/passport/web/auth/uamtk",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -16,7 +16,7 @@ urls = {
|
|||
"login": {
|
||||
"req_url": "/passport/web/login",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/login/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -25,9 +25,9 @@ urls = {
|
|||
|
||||
},
|
||||
"getCodeImg": {
|
||||
"req_url": "/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}".format(random.random()),
|
||||
"req_url": "/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}",
|
||||
"req_type": "get",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/login/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -37,7 +37,7 @@ urls = {
|
|||
"codeCheck": {
|
||||
"req_url": "/passport/captcha/captcha-check",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/login/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -47,9 +47,9 @@ urls = {
|
|||
"loginInit": {
|
||||
"req_url": "/otn/login/init",
|
||||
"req_type": "get",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/index/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 1,
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
"is_logger": False,
|
||||
"is_json": False,
|
||||
|
@ -57,7 +57,7 @@ urls = {
|
|||
"getUserInfo": {
|
||||
"req_url": "/otn/index/initMy12306",
|
||||
"req_type": "get",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -67,7 +67,7 @@ urls = {
|
|||
"userLogin": {
|
||||
"req_url": "/otn/login/userLogin",
|
||||
"req_type": "get",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -77,7 +77,7 @@ urls = {
|
|||
"uamauthclient": {
|
||||
"req_url": "/otn/uamauthclient",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -87,7 +87,7 @@ urls = {
|
|||
"initdc_url": {
|
||||
"req_url": "/otn/confirmPassenger/initDc",
|
||||
"req_type": "get",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/leftTicket/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -97,7 +97,7 @@ urls = {
|
|||
"get_passengerDTOs": {
|
||||
"req_url": "/otn/confirmPassenger/getPassengerDTOs",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -107,7 +107,7 @@ urls = {
|
|||
"select_url": {
|
||||
"req_url": "/otn/leftTicket/queryZ?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/leftTicket/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -117,17 +117,17 @@ urls = {
|
|||
"check_user_url": {
|
||||
"req_url": "/otn/login/checkUser",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/leftTicket/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 1,
|
||||
"re_time": 0.1,
|
||||
"re_try": 10,
|
||||
"re_time": 0.3,
|
||||
"is_logger": True,
|
||||
"is_json": True,
|
||||
},
|
||||
"submit_station_url": {
|
||||
"req_url": "/otn/leftTicket/submitOrderRequest",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/leftTicket/init",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -137,7 +137,7 @@ urls = {
|
|||
"checkOrderInfoUrl": {
|
||||
"req_url": "/otn/confirmPassenger/checkOrderInfo",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -147,7 +147,7 @@ urls = {
|
|||
"getQueueCountUrl": {
|
||||
"req_url": "/otn/confirmPassenger/getQueueCount",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -157,7 +157,7 @@ urls = {
|
|||
"checkQueueOrderUrl": {
|
||||
"req_url": "/otn/confirmPassenger/confirmSingleForQueue",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -167,7 +167,7 @@ urls = {
|
|||
"checkRandCodeAnsyn": {
|
||||
"req_url": "/otn/passcodeNew/checkRandCodeAnsyn",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -177,7 +177,7 @@ urls = {
|
|||
"codeImgByOrder": {
|
||||
"req_url": "/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&%s" % random.random(),
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -187,7 +187,7 @@ urls = {
|
|||
"queryOrderWaitTimeUrl": {
|
||||
"req_url": "/otn/confirmPassenger/queryOrderWaitTime",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -197,7 +197,7 @@ urls = {
|
|||
"queryMyOrderNoCompleteUrl": {
|
||||
"req_url": "/otn/queryOrder/queryMyOrderNoComplete",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -207,7 +207,7 @@ urls = {
|
|||
"initNoCompleteUrl": {
|
||||
"req_url": "/otn/queryOrder/initNoComplete",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
@ -217,7 +217,7 @@ urls = {
|
|||
"cancelNoCompleteMyOrder": {
|
||||
"req_url": "/otn/queryOrder/cancelNoCompleteMyOrder",
|
||||
"req_type": "post",
|
||||
"Referer": "",
|
||||
"Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",
|
||||
"Host": "kyfw.12306.cn",
|
||||
"re_try": 10,
|
||||
"re_time": 0.1,
|
||||
|
|
|
@ -24,7 +24,7 @@ class GoLogin:
|
|||
self.aotu_code_type = aotu_code_type
|
||||
|
||||
def cookietp(self):
|
||||
print("正在获取cookie")
|
||||
print(u"正在获取cookie")
|
||||
url = self.urlConf["loginInit"]
|
||||
self.httpClint.send(url)
|
||||
# Url = "https://kyfw.12306.cn/otn/login/init"
|
||||
|
@ -67,12 +67,12 @@ class GoLogin:
|
|||
3.控制台输入对应下标,按照英文逗号分开,即可手动完成打码,
|
||||
:return:
|
||||
"""
|
||||
print ("下载验证码...")
|
||||
print (u"下载验证码...")
|
||||
codeimgUrl = code_url
|
||||
img_path = './tkcode'
|
||||
result = self.httpClint.send(codeimgUrl)
|
||||
try:
|
||||
print("下载验证码成功")
|
||||
print(u"下载验证码成功")
|
||||
open(img_path, 'wb').write(result)
|
||||
except OSError as e:
|
||||
print (e)
|
||||
|
@ -83,7 +83,7 @@ class GoLogin:
|
|||
:return: str
|
||||
"""
|
||||
if is_raw_input:
|
||||
Ofset = raw_input("请输入验证码: ")
|
||||
Ofset = raw_input(u"请输入验证码: ")
|
||||
select = Ofset.split(',')
|
||||
post = []
|
||||
offsetsX = 0 # 选择的答案的left值,通过浏览器点击8个小图的中点得到的,这样基本没问题
|
||||
|
@ -118,7 +118,7 @@ class GoLogin:
|
|||
post.append(offsetsX)
|
||||
post.append(offsetsY)
|
||||
randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
|
||||
print("验证码识别坐标为{0}".format(randCode))
|
||||
print(u"验证码识别坐标为{0}".format(randCode))
|
||||
return randCode
|
||||
|
||||
def auth(self):
|
||||
|
@ -141,7 +141,7 @@ class GoLogin:
|
|||
}
|
||||
fresult = self.httpClint.send(codeCheck, codeCheckData)
|
||||
if "result_code" in fresult and fresult["result_code"] == "4":
|
||||
print ("验证码通过,开始登录..")
|
||||
print (u"验证码通过,开始登录..")
|
||||
return True
|
||||
else:
|
||||
if "result_message" in fresult:
|
||||
|
@ -164,7 +164,7 @@ class GoLogin:
|
|||
}
|
||||
tresult = self.httpClint.send(logurl, logData)
|
||||
if 'result_code' in tresult and tresult["result_code"] == 0:
|
||||
print ("登录成功")
|
||||
print (u"登录成功")
|
||||
tk = self.auth()
|
||||
if "newapptk" in tk and tk["newapptk"]:
|
||||
return tk["newapptk"]
|
||||
|
@ -172,11 +172,11 @@ class GoLogin:
|
|||
return False
|
||||
elif 'result_message' in tresult and tresult['result_message']:
|
||||
messages = tresult['result_message']
|
||||
if messages.find("密码输入错误") is not -1:
|
||||
if messages.find(u"密码输入错误") is not -1:
|
||||
raise UserPasswordException("{0}".format(messages))
|
||||
else:
|
||||
print ("登录失败: {0}".format(messages))
|
||||
print ("尝试重新登陆")
|
||||
print (u"登录失败: {0}".format(messages))
|
||||
print (u"尝试重新登陆")
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
@ -187,14 +187,14 @@ class GoLogin:
|
|||
:return:
|
||||
"""
|
||||
if not uamtk:
|
||||
return "权限校验码不能为空"
|
||||
return u"权限校验码不能为空"
|
||||
else:
|
||||
uamauthclientUrl = self.urlConf["uamauthclient"]
|
||||
data = {"tk": uamtk}
|
||||
uamauthclientResult = self.httpClint.send(uamauthclientUrl, data)
|
||||
if uamauthclientResult:
|
||||
if "result_code" in uamauthclientResult and uamauthclientResult["result_code"] == 0:
|
||||
print("欢迎 {} 登录".format(uamauthclientResult["username"]))
|
||||
print(u"欢迎 {} 登录".format(uamauthclientResult["username"]))
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -213,14 +213,15 @@ class GoLogin:
|
|||
if self.is_aotu_code and self.aotu_code_type == 1:
|
||||
balance = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"]).getBalance()
|
||||
if int(balance) < 40:
|
||||
raise balanceException('余额不足,当前余额为: {}'.format(balance))
|
||||
raise balanceException(u'余额不足,当前余额为: {}'.format(balance))
|
||||
user, passwd = _get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"]
|
||||
if not user or not passwd:
|
||||
raise UserPasswordException("温馨提示: 用户名或者密码为空,请仔细检查")
|
||||
raise UserPasswordException(u"温馨提示: 用户名或者密码为空,请仔细检查")
|
||||
login_num = 0
|
||||
while True:
|
||||
self.cookietp()
|
||||
self.httpClint.set_cookies(_jc_save_wfdc_flag="dc", _jc_save_fromStation="%u4E0A%u6D77%u8679%u6865%2CAOH", _jc_save_toStation="%u5170%u5DDE%u897F%2CLAJ", _jc_save_fromDate="2018-02-14", _jc_save_toDate="2018-01-16", RAIL_DEVICEID="EN_3_EGSe2GWGHXJeCkFQ52kHvNCrNlkz9n1GOqqQ1wR0i98WsD8Gj-a3YHZ-XYKeESWgCiJyyucgSwkFOzVHhHqfpidLPcm2vK9n83uzOPuShO3Pl4lCydAtQu4BdFqz-RVmiduNFixrcrN_Ny43135JiEtqLaI")
|
||||
self.urlConf["getCodeImg"]["req_url"] = self.urlConf["getCodeImg"]["req_url"].format(random.random())
|
||||
self.readImg(self.urlConf["getCodeImg"])
|
||||
self.randCode = self.getRandCode()
|
||||
login_num += 1
|
||||
|
@ -235,9 +236,9 @@ class GoLogin:
|
|||
url = 'https://kyfw.12306.cn/otn/login/loginOut'
|
||||
result = myurllib2.get(url)
|
||||
if result:
|
||||
print ("已退出")
|
||||
print (u"已退出")
|
||||
else:
|
||||
print ("退出失败")
|
||||
print (u"退出失败")
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding=utf-8 -*-
|
||||
import datetime
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
|
@ -31,6 +32,7 @@ class select:
|
|||
self.from_station, self.to_station, self.station_dates, self._station_seat, self.is_more_ticket, self.ticke_peoples, self.select_refresh_interval, self.station_trains, self.ticket_black_list_time = self.get_ticket_info()
|
||||
self.is_aotu_code = _get_yaml()["is_aotu_code"]
|
||||
self.aotu_code_type = _get_yaml()["aotu_code_type"]
|
||||
self.is_cdn = _get_yaml()["is_cdn"]
|
||||
self.order_request_params = {} # 订单提交时的参数
|
||||
self.ticketInfoForPassengerForm = {} # 初始化当前页面参数
|
||||
self.current_seats = {} # 席别信息
|
||||
|
@ -63,7 +65,7 @@ class select:
|
|||
station_trains = ticket_info_config["set"]["station_trains"]
|
||||
ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
|
||||
print "*"*20
|
||||
print "当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n".format\
|
||||
print u"当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n".format\
|
||||
(
|
||||
from_station,
|
||||
to_station,
|
||||
|
@ -203,8 +205,8 @@ class select:
|
|||
elif 'messages' in jsonData and jsonData['messages']:
|
||||
print(jsonData['messages'][0])
|
||||
else:
|
||||
print("未查找到常用联系人")
|
||||
raise PassengerUserException("未查找到常用联系人,请先添加联系人在试试")
|
||||
print(u"未查找到常用联系人")
|
||||
raise PassengerUserException(u"未查找到常用联系人,请先添加联系人在试试")
|
||||
|
||||
def submitOrderRequestFunc(self, from_station, to_station, station_date=None):
|
||||
self.confUrl["select_url"]["req_url"] = self.confUrl["select_url"]["req_url"].format(
|
||||
|
@ -231,7 +233,7 @@ class select:
|
|||
for station_ticket in station_tickets:
|
||||
value = station_ticket['data']
|
||||
if not value:
|
||||
print ('{0}-{1} 车次坐席查询为空...'.format(self.from_station, self.to_station))
|
||||
print (u'{0}-{1} 车次坐席查询为空...'.format(self.from_station, self.to_station))
|
||||
else:
|
||||
if value['result']:
|
||||
for i in value['result']:
|
||||
|
@ -244,13 +246,13 @@ class select:
|
|||
# tiket_values = [k for k in value['map'].values()]
|
||||
self.secretStr = ticket_info[0]
|
||||
train_no = ticket_info[3]
|
||||
print ('车次: ' + train_no + ' 始发车站: ' + self.from_station + ' 终点站: ' +
|
||||
print (u'车次: ' + train_no + ' 始发车站: ' + self.from_station + ' 终点站: ' +
|
||||
self.to_station + ' ' + self._station_seat[j].encode("utf8") + ':' + ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))])
|
||||
if self.ticket_black_list.has_key(train_no) and (datetime.datetime.now() - self.ticket_black_list[train_no]).seconds/60 < int(self.ticket_black_list_time):
|
||||
print("该车次{} 正在被关小黑屋,跳过此车次".format(train_no))
|
||||
print(u"该车次{} 正在被关小黑屋,跳过此车次".format(train_no))
|
||||
break
|
||||
else:
|
||||
print ('正在尝试提交订票...')
|
||||
print (u'正在尝试提交订票...')
|
||||
|
||||
# self.submitOrderRequestFunc(from_station, to_station, self.time())
|
||||
self.submit_station()
|
||||
|
@ -266,7 +268,7 @@ class select:
|
|||
pass
|
||||
# time.sleep(self.expect_refresh_interval)
|
||||
else:
|
||||
print "车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket)
|
||||
print u"车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket)
|
||||
|
||||
def check_user(self):
|
||||
"""
|
||||
|
@ -281,13 +283,13 @@ class select:
|
|||
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||
else:
|
||||
if check_user['messages']:
|
||||
print ('用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0])
|
||||
print ('正在尝试重新登录')
|
||||
print (u'用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0])
|
||||
print (u'正在尝试重新登录')
|
||||
self.call_login()
|
||||
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||
else:
|
||||
print ('用户检查失败: %s,可能未登录,可能session已经失效' % check_user)
|
||||
print ('正在尝试重新登录')
|
||||
print (u'用户检查失败: %s,可能未登录,可能session已经失效' % check_user)
|
||||
print (u'正在尝试重新登录')
|
||||
self.call_login()
|
||||
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||
|
||||
|
@ -313,9 +315,9 @@ class select:
|
|||
submitResult = self.httpClint.send(submit_station_url, data)
|
||||
if 'data' in submitResult and submitResult['data']:
|
||||
if submitResult['data'] == 'N':
|
||||
print ('出票成功')
|
||||
print (u'出票成功')
|
||||
else:
|
||||
print ('出票失败')
|
||||
print (u'出票失败')
|
||||
elif 'messages' in submitResult and submitResult['messages']:
|
||||
raise ticketIsExitsException(submitResult['messages'][0])
|
||||
|
||||
|
@ -352,7 +354,7 @@ class select:
|
|||
passengerTicketStrList = []
|
||||
oldPassengerStr = []
|
||||
if not self.user_info:
|
||||
raise PassengerUserException("联系人不在列表中,请查证后添加")
|
||||
raise PassengerUserException(u"联系人不在列表中,请查证后添加")
|
||||
if len(self.user_info) is 1:
|
||||
passengerTicketStrList.append(
|
||||
'0,' + self.user_info[0]['passenger_type'] + "," + self.user_info[0][
|
||||
|
@ -394,12 +396,10 @@ class select:
|
|||
if 'data' in checkOrderInfo:
|
||||
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo["data"]["ifShowPassCode"] == "Y":
|
||||
is_need_code = True
|
||||
t = threading.Thread(target=self.callRandCode())
|
||||
t.start()
|
||||
if self.getQueueCount(train_no, set_type, is_need_code):
|
||||
return True
|
||||
if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo['data']['submitStatus'] is True:
|
||||
print ('车票提交通过,正在尝试排队')
|
||||
print (u'车票提交通过,正在尝试排队')
|
||||
is_need_code = False
|
||||
if self.getQueueCount(train_no, set_type, is_need_code):
|
||||
return True
|
||||
|
@ -442,25 +442,25 @@ class select:
|
|||
countT = getQueueCountResult["data"]["countT"]
|
||||
if int(countT) is 0:
|
||||
if int(ticket_split) < len(self.user_info):
|
||||
print("当前余票数小于乘车人数,放弃订票")
|
||||
print(u"当前余票数小于乘车人数,放弃订票")
|
||||
else:
|
||||
print("排队成功, 当前余票还剩余: {0} 张".format(ticket_split))
|
||||
print(u"排队成功, 当前余票还剩余: {0} 张".format(ticket_split))
|
||||
if self.checkQueueOrder(is_need_code):
|
||||
return True
|
||||
else:
|
||||
print("当前排队人数:" + str(countT) + "当前余票还剩余:{0} 张,继续排队中".format(ticket_split))
|
||||
print(u"当前排队人数: {1} 当前余票还剩余:{0} 张,继续排队中".format(ticket_split, countT))
|
||||
else:
|
||||
print("排队发现未知错误{0},将此列车 {1}加入小黑屋".format(getQueueCountResult, train_no))
|
||||
print(u"排队发现未知错误{0},将此列车 {1}加入小黑屋".format(getQueueCountResult, train_no))
|
||||
self.ticket_black_list[train_no] = datetime.datetime.now()
|
||||
elif "messages" in getQueueCountResult and getQueueCountResult["messages"]:
|
||||
print("排队异常,错误信息:{0}, 将此列车 {1}加入小黑屋".format(getQueueCountResult["messages"][0], train_no))
|
||||
print(u"排队异常,错误信息:{0}, 将此列车 {1}加入小黑屋".format(getQueueCountResult["messages"][0], train_no))
|
||||
self.ticket_black_list[train_no] = datetime.datetime.now()
|
||||
else:
|
||||
if "validateMessages" in getQueueCountResult and getQueueCountResult["validateMessages"]:
|
||||
print(str(getQueueCountResult["validateMessages"]))
|
||||
self.ticket_black_list[train_no] = datetime.datetime.now()
|
||||
else:
|
||||
print("未知错误 {0}".format("".join(getQueueCountResult)))
|
||||
print(u"未知错误 {0}".format("".join(getQueueCountResult)))
|
||||
|
||||
def checkRandCodeAnsyn(self, randCode):
|
||||
"""
|
||||
|
@ -502,40 +502,40 @@ class select:
|
|||
|
||||
try:
|
||||
if is_node_code:
|
||||
print("正在使用自动识别验证码功能")
|
||||
print(u"正在使用自动识别验证码功能")
|
||||
for i in range(3):
|
||||
codeImgByOrder = self.confUrl["codeImgByOrder"]
|
||||
self.login.readImg(codeImgByOrder)
|
||||
randCode = self.login.getRandCode()
|
||||
checkcode = self.checkRandCodeAnsyn(randCode)
|
||||
if checkcode == 'TRUE':
|
||||
print("验证码通过,正在提交订单")
|
||||
print(u"验证码通过,正在提交订单")
|
||||
data['randCode'] = randCode
|
||||
break
|
||||
else:
|
||||
print ("验证码有误, {0}次尝试重试".format(i+1))
|
||||
print("验证码超过限定次数3次,放弃此次订票机会!")
|
||||
print (u"验证码有误, {0}次尝试重试".format(i+1))
|
||||
print(u"验证码超过限定次数3次,放弃此次订票机会!")
|
||||
else:
|
||||
print("不需要验证码")
|
||||
print(u"不需要验证码")
|
||||
time.sleep(0.5)
|
||||
checkQueueOrderResult = self.httpClint.send(checkQueueOrderUrl, data)
|
||||
if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]:
|
||||
c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {}
|
||||
if 'submitStatus' in c_data and c_data['submitStatus'] is True:
|
||||
print("提交订单成功!")
|
||||
print(u"提交订单成功!")
|
||||
self.queryOrderWaitTime()
|
||||
else:
|
||||
if 'errMsg' in c_data and c_data['errMsg']:
|
||||
print("提交订单失败,{0}".format(c_data['errMsg']))
|
||||
print(u"提交订单失败,{0}".format(c_data['errMsg']))
|
||||
else:
|
||||
print(c_data)
|
||||
print('订票失败!很抱歉,请重试提交预订功能!')
|
||||
print(u'订票失败!很抱歉,请重试提交预订功能!')
|
||||
elif "messages" in checkQueueOrderResult and checkQueueOrderResult["messages"]:
|
||||
print("提交订单失败,错误信息: " + checkQueueOrderResult["messages"])
|
||||
print(u"提交订单失败,错误信息: " + checkQueueOrderResult["messages"])
|
||||
else:
|
||||
print("提交订单中,请耐心等待:" + checkQueueOrderResult["message"])
|
||||
print(u"提交订单中,请耐心等待:" + checkQueueOrderResult["message"])
|
||||
except ValueError:
|
||||
print("接口 {} 无响应".format(checkQueueOrderUrl))
|
||||
print(u"接口 {} 无响应".format(checkQueueOrderUrl))
|
||||
|
||||
def queryOrderWaitTime(self):
|
||||
"""
|
||||
|
@ -547,7 +547,7 @@ class select:
|
|||
_random = int(round(time.time() * 1000))
|
||||
num += 1
|
||||
if num > 30:
|
||||
print("超出排队时间,自动放弃,正在重新刷票")
|
||||
print(u"超出排队时间,自动放弃,正在重新刷票")
|
||||
order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单
|
||||
if order_id:
|
||||
self.cancelNoCompleteMyOrder(order_id)
|
||||
|
@ -561,25 +561,25 @@ 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"]))
|
||||
sendEmail(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"]))
|
||||
raise ticketIsExitsException(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"]))
|
||||
elif "msg" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["msg"]:
|
||||
print queryOrderWaitTimeResult["data"]["msg"]
|
||||
break
|
||||
elif "waitTime"in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["waitTime"]:
|
||||
print("排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"]))
|
||||
print(u"排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"]))
|
||||
else:
|
||||
print ("正在等待中")
|
||||
elif "messages" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["messages"]:
|
||||
print("排队等待失败: " + queryOrderWaitTimeResult["messages"])
|
||||
print(u"排队等待失败: " + queryOrderWaitTimeResult["messages"])
|
||||
else:
|
||||
print("第{}次排队中,请耐心等待".format(num+1))
|
||||
print(u"第{}次排队中,请耐心等待".format(num+1))
|
||||
else:
|
||||
print("排队中")
|
||||
print(u"排队中")
|
||||
time.sleep(2)
|
||||
|
||||
else:
|
||||
print(ticketNumOutException("订单提交失败!,正在重新刷票"))
|
||||
print(ticketNumOutException(u"订单提交失败!,正在重新刷票"))
|
||||
|
||||
def queryMyOrderNoComplete(self):
|
||||
"""
|
||||
|
@ -608,7 +608,7 @@ class select:
|
|||
else:
|
||||
return False
|
||||
else:
|
||||
print("接口 {} 无响应".format(queryMyOrderNoCompleteUrl))
|
||||
print(u"接口 {} 无响应".format(queryMyOrderNoCompleteUrl))
|
||||
|
||||
def initNoComplete(self):
|
||||
"""
|
||||
|
@ -634,19 +634,24 @@ class select:
|
|||
}
|
||||
cancelNoCompleteMyOrderResult = self.httpClint.send(cancelNoCompleteMyOrderUrl, cancelNoCompleteMyOrderData)
|
||||
if "data" in cancelNoCompleteMyOrderResult and "existError" in cancelNoCompleteMyOrderResult["data"] and cancelNoCompleteMyOrderResult["data"]["existError"] == "N":
|
||||
print("排队超时,已为您自动取消订单,订单编号: {0}".format(sequence_no))
|
||||
print(u"排队超时,已为您自动取消订单,订单编号: {0}".format(sequence_no))
|
||||
time.sleep(2)
|
||||
return True
|
||||
else:
|
||||
print("排队超时,取消订单失败, 订单号{0}".format(sequence_no))
|
||||
print(u"排队超时,取消订单失败, 订单号{0}".format(sequence_no))
|
||||
|
||||
def set_cdn(self):
|
||||
"""
|
||||
设置cdn
|
||||
:return:
|
||||
"""
|
||||
# self.httpClint.cdn = eval(self.cdn_list[random.randint(0, len(self.cdn_list)-1)])["result"].replace("'", "")
|
||||
self.httpClint.cdn = self.cdn_list
|
||||
if self.is_cdn == 1:
|
||||
while True:
|
||||
if self.cdn_list:
|
||||
self.httpClint.cdn = self.cdn_list[random.randint(0, len(self.cdn_list)-1)]
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
||||
def call_login(self, auth=False):
|
||||
"""
|
||||
|
@ -658,17 +663,37 @@ class select:
|
|||
else:
|
||||
self.login.go_login()
|
||||
|
||||
def main(self):
|
||||
is_cdn = _get_yaml()["is_cdn"]
|
||||
if is_cdn == 1:
|
||||
def cdn_req(self, cdn):
|
||||
for i in range(len(cdn)-1):
|
||||
http = HTTPClient()
|
||||
urls = self.confUrl["loginInit"]
|
||||
start_time = datetime.datetime.now()
|
||||
http.cdn = cdn[i].replace("\n", "")
|
||||
rep = http.send(urls)
|
||||
if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 400:
|
||||
self.cdn_list.append(cdn[i].replace("\n", ""))
|
||||
|
||||
def cdn_certification(self):
|
||||
"""
|
||||
cdn 认证
|
||||
:return:
|
||||
"""
|
||||
if self.is_cdn == 1:
|
||||
CDN = CDNProxy()
|
||||
self.cdn_list = CDN.all_cdn()
|
||||
if self.cdn_list:
|
||||
print("开启cdn查询")
|
||||
print("本次cdn总数为{}".format(len(self.cdn_list)))
|
||||
self.set_cdn()
|
||||
all_cdn = CDN.all_cdn()
|
||||
if all_cdn:
|
||||
print(u"开启cdn查询")
|
||||
print(u"本次待筛选cdn总数为{}".format(len(all_cdn)))
|
||||
t = threading.Thread(target=self.cdn_req, args=(all_cdn,))
|
||||
t.start()
|
||||
else:
|
||||
raise ticketConfigException("cdn列表为空,请先加载cdn")
|
||||
raise ticketConfigException(u"cdn列表为空,请先加载cdn")
|
||||
else:
|
||||
pass
|
||||
|
||||
def main(self):
|
||||
self.cdn_certification()
|
||||
self.set_cdn()
|
||||
self.call_login()
|
||||
from_station, to_station = self.station_table(self.from_station, self.to_station)
|
||||
self.check_user()
|
||||
|
@ -682,14 +707,17 @@ class select:
|
|||
self.check_user()
|
||||
time.sleep(self.select_refresh_interval)
|
||||
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00":
|
||||
print "12306休息时间,本程序自动停止,明天早上6点将自动运行"
|
||||
print u"12306休息时间,本程序自动停止,明天早上6点将自动运行"
|
||||
time.sleep(60 * 60 * 7)
|
||||
self.call_login()
|
||||
start_time = datetime.datetime.now()
|
||||
self.submitOrderRequestImplement(from_station, to_station)
|
||||
print "正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 cdn轮询IP {4} 总耗时{3}ms".format(num, ",".join(self.station_dates), ",".join(self.station_trains), (datetime.datetime.now()-start_time).microseconds/1000, self.httpClint.cdn)
|
||||
if is_cdn == 1:
|
||||
self.set_cdn()
|
||||
print u"正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 cdn轮询IP {4} 当前cdn总数{5} 总耗时{3}ms".format(num,
|
||||
",".join(self.station_dates),
|
||||
",".join(self.station_trains),
|
||||
(datetime.datetime.now()-start_time).microseconds/1000, self.httpClint.cdn,
|
||||
len(self.cdn_list))
|
||||
self.set_cdn()
|
||||
except PassengerUserException as e:
|
||||
print e.message
|
||||
break
|
||||
|
@ -707,13 +735,13 @@ class select:
|
|||
break
|
||||
except ValueError as e:
|
||||
if e.message == "No JSON object could be decoded":
|
||||
print("12306接口无响应,正在重试")
|
||||
print(u"12306接口无响应,正在重试")
|
||||
else:
|
||||
print(e.message)
|
||||
except KeyError as e:
|
||||
print(e.message)
|
||||
except TypeError as e:
|
||||
print("12306接口无响应,正在重试 {0}".format(e.message))
|
||||
print(u"12306接口无响应,正在重试 {0}".format(e.message))
|
||||
except socket.error as e:
|
||||
print(e.message)
|
||||
|
||||
|
|
|
@ -90,7 +90,8 @@ class HTTPClient(object):
|
|||
"""send request to url.If response 200,return response, else return None."""
|
||||
allow_redirects = False
|
||||
is_logger = urls["is_logger"]
|
||||
error_data = {"code": 99999, "message": "重试次数达到上限"}
|
||||
error_data = {"code": 99999, "message": u"重试次数达到上限"}
|
||||
self.setHeadersReferer(urls["Referer"])
|
||||
if data:
|
||||
method = "post"
|
||||
self.setHeaders({"Content-Length": "{0}".format(len(data))})
|
||||
|
@ -107,7 +108,6 @@ class HTTPClient(object):
|
|||
url_host = urls["Host"]
|
||||
for i in range(urls["re_try"]):
|
||||
try:
|
||||
print("https://" + url_host + urls["req_url"])
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
response = self._s.request(method=method,
|
||||
timeout=2,
|
||||
|
@ -116,7 +116,6 @@ class HTTPClient(object):
|
|||
allow_redirects=allow_redirects,
|
||||
verify=False,
|
||||
**kwargs)
|
||||
print(response.status_code)
|
||||
if response.status_code == 200:
|
||||
if response.content:
|
||||
if is_logger:
|
||||
|
|
Loading…
Reference in New Issue