parent
cd65eeb963
commit
501fd388bd
|
@ -159,4 +159,9 @@
|
||||||
- 需要开启打码兔代码功能,is_aotu_code 设置为True
|
- 需要开启打码兔代码功能,is_aotu_code 设置为True
|
||||||
- 增加异常判断
|
- 增加异常判断
|
||||||
|
|
||||||
|
- 2018.1.15更新
|
||||||
|
- 增加捡漏自动检测是否登录功能,建议捡漏不要刷新太快,2S最好,否则会封IP
|
||||||
|
- 优化提交订单有很大记录无限排队的情况,感谢群里的小伙伴提供的思路
|
||||||
|
- 修改休眠时间为早上6点
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
|
@ -111,13 +112,14 @@ def codexy():
|
||||||
randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
|
randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '')
|
||||||
|
|
||||||
|
|
||||||
def login(user, passwd):
|
def go_login():
|
||||||
"""
|
"""
|
||||||
登陆
|
登陆
|
||||||
:param user: 账户名
|
:param user: 账户名
|
||||||
:param passwd: 密码
|
:param passwd: 密码
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
user, passwd = _get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"]
|
||||||
login_num = 0
|
login_num = 0
|
||||||
while True:
|
while True:
|
||||||
cookietp()
|
cookietp()
|
||||||
|
@ -166,7 +168,16 @@ def login(user, passwd):
|
||||||
getUserinfo()
|
getUserinfo()
|
||||||
break
|
break
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
errorinput(e)
|
if e.message == "No JSON object could be decoded":
|
||||||
|
print("12306接口无响应,正在重试")
|
||||||
|
else:
|
||||||
|
print(e.message)
|
||||||
|
except KeyError as e:
|
||||||
|
print(e.message)
|
||||||
|
except TypeError as e:
|
||||||
|
print(e.message)
|
||||||
|
except socket.error as e:
|
||||||
|
print(e.message)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,10 +197,6 @@ def getUserinfo():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
login(_get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"])
|
|
||||||
|
|
||||||
|
|
||||||
def logout():
|
def logout():
|
||||||
url = 'https://kyfw.12306.cn/otn/login/loginOut'
|
url = 'https://kyfw.12306.cn/otn/login/loginOut'
|
||||||
result = myurllib2.get(url)
|
result = myurllib2.get(url)
|
||||||
|
|
|
@ -14,7 +14,7 @@ from init import login
|
||||||
from config.emailConf import sendEmail
|
from config.emailConf import sendEmail
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
from damatuCode.damatuWeb import DamatuApi
|
from damatuCode.damatuWeb import DamatuApi
|
||||||
from init.login import login
|
from init.login import go_login
|
||||||
from myException.PassengerUserException import PassengerUserException
|
from myException.PassengerUserException import PassengerUserException
|
||||||
from myException.ticketConfigException import ticketConfigException
|
from myException.ticketConfigException import ticketConfigException
|
||||||
from myException.ticketIsExitsException import ticketIsExitsException
|
from myException.ticketIsExitsException import ticketIsExitsException
|
||||||
|
@ -36,6 +36,7 @@ class select:
|
||||||
self.user_info = ""
|
self.user_info = ""
|
||||||
self.secretStr = ""
|
self.secretStr = ""
|
||||||
self.ticket_black_list = dict()
|
self.ticket_black_list = dict()
|
||||||
|
self.is_check_user = dict()
|
||||||
|
|
||||||
def get_ticket_info(self):
|
def get_ticket_info(self):
|
||||||
"""
|
"""
|
||||||
|
@ -225,7 +226,6 @@ class select:
|
||||||
else:
|
else:
|
||||||
print ('正在尝试提交订票...')
|
print ('正在尝试提交订票...')
|
||||||
# self.submitOrderRequestFunc(from_station, to_station, self.time())
|
# self.submitOrderRequestFunc(from_station, to_station, self.time())
|
||||||
if self.check_user():
|
|
||||||
self.submit_station()
|
self.submit_station()
|
||||||
self.getPassengerTicketStr(self._station_seat[j].encode("utf8"))
|
self.getPassengerTicketStr(self._station_seat[j].encode("utf8"))
|
||||||
self.getRepeatSubmitToken()
|
self.getRepeatSubmitToken()
|
||||||
|
@ -251,13 +251,18 @@ class select:
|
||||||
check_user = json.loads(myurllib2.Post(check_user_url, data), encoding='utf-8')
|
check_user = json.loads(myurllib2.Post(check_user_url, data), encoding='utf-8')
|
||||||
check_user_flag = check_user['data']['flag']
|
check_user_flag = check_user['data']['flag']
|
||||||
if check_user_flag is True:
|
if check_user_flag is True:
|
||||||
print ('尝试提交订单...')
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
if check_user['messages']:
|
if check_user['messages']:
|
||||||
print ('用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0])
|
print ('用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0])
|
||||||
|
print ('正在尝试重新登录')
|
||||||
|
self.call_login()
|
||||||
|
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||||
else:
|
else:
|
||||||
print ('用户检查失败: %s,可能未登录,可能session已经失效' % check_user)
|
print ('用户检查失败: %s,可能未登录,可能session已经失效' % check_user)
|
||||||
|
print ('正在尝试重新登录')
|
||||||
|
self.call_login()
|
||||||
|
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||||
|
|
||||||
def submit_station(self):
|
def submit_station(self):
|
||||||
"""
|
"""
|
||||||
|
@ -601,18 +606,26 @@ class select:
|
||||||
# else:
|
# else:
|
||||||
# self.submitOrderRequest()
|
# self.submitOrderRequest()
|
||||||
|
|
||||||
|
def call_login(self):
|
||||||
|
"""登录回调方法"""
|
||||||
|
go_login()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
self.call_login()
|
||||||
from_station, to_station = self.station_table(self.from_station, self.to_station)
|
from_station, to_station = self.station_table(self.from_station, self.to_station)
|
||||||
# if self.leftTicketLog(from_station, to_station):
|
# if self.leftTicketLog(from_station, to_station):
|
||||||
num = 1
|
num = 1
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
num += 1
|
num += 1
|
||||||
|
if "user_time" in self.is_check_user and (datetime.datetime.now() - self.is_check_user["user_time"]).seconds/60 > 10:
|
||||||
|
# 十分钟调用一次检查用户是否登录
|
||||||
|
self.check_user()
|
||||||
time.sleep(self.select_refresh_interval)
|
time.sleep(self.select_refresh_interval)
|
||||||
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00":
|
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00":
|
||||||
print "12306休息时间,本程序自动停止,明天早上七点将自动运行"
|
print "12306休息时间,本程序自动停止,明天早上6点将自动运行"
|
||||||
time.sleep(28800)
|
time.sleep(60 * 60 * 7)
|
||||||
login.main() # 重新登录
|
self.call_login()
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
self.submitOrderRequestImplement(from_station, to_station)
|
self.submitOrderRequestImplement(from_station, to_station)
|
||||||
print "正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 代理设置 无 总耗时{3}ms".format(num, self.station_date, ",".join(self.station_trains), (datetime.datetime.now()-start_time).microseconds/1000)
|
print "正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 代理设置 无 总耗时{3}ms".format(num, self.station_date, ",".join(self.station_trains), (datetime.datetime.now()-start_time).microseconds/1000)
|
||||||
|
@ -643,7 +656,7 @@ class select:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
a = select('上海', '北京')
|
login()
|
||||||
a.main()
|
# a = select('上海', '北京')
|
||||||
|
# a.main()
|
|
@ -20,9 +20,9 @@ def get(url):
|
||||||
request = urllib2.Request(url=url)
|
request = urllib2.Request(url=url)
|
||||||
request.add_header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
|
request.add_header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
|
||||||
request.add_header('X-Requested-With', 'xmlHttpRequest')
|
request.add_header('X-Requested-With', 'xmlHttpRequest')
|
||||||
request.add_header('User-Agent',
|
request.add_header('User-Agent', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
|
||||||
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36')
|
)
|
||||||
request.add_header('Referer', 'https://kyfw.12306.cn/otn/login/init')
|
request.add_header('Referer', 'https://kyfw.12306.cn/otn/confirmPassenger/initDc')
|
||||||
request.add_header('Accept', '*/*')
|
request.add_header('Accept', '*/*')
|
||||||
result = urllib2.urlopen(request).read()
|
result = urllib2.urlopen(request).read()
|
||||||
assert isinstance(result, object)
|
assert isinstance(result, object)
|
||||||
|
@ -44,9 +44,9 @@ def Post(url, data):
|
||||||
# request = urllib2Post.Request(ajax_url, urllib.urlencode(dc))
|
# request = urllib2Post.Request(ajax_url, urllib.urlencode(dc))
|
||||||
request.add_header("Content-Type", "application/x-www-form-urlencoded;application/json;charset=utf-8")
|
request.add_header("Content-Type", "application/x-www-form-urlencoded;application/json;charset=utf-8")
|
||||||
request.add_header('X-Requested-With', 'xmlHttpRequest')
|
request.add_header('X-Requested-With', 'xmlHttpRequest')
|
||||||
request.add_header('User-Agent',
|
request.add_header('User-Agent', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
|
||||||
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36')
|
)
|
||||||
request.add_header('Referer', 'https://kyfw.12306.cn/otn/login/init')
|
request.add_header('Referer', 'https://kyfw.12306.cn/otn/confirmPassenger/initDc')
|
||||||
request.add_header('Accept', '*/*')
|
request.add_header('Accept', '*/*')
|
||||||
# request.add_header('Accept-Encoding', 'gzip, deflate')
|
# request.add_header('Accept-Encoding', 'gzip, deflate')
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
|
|
Loading…
Reference in New Issue