mirror of https://github.com/testerSunshine/12306
恢复cdn功能,优化显示
parent
bbee85ff1b
commit
b88834cdfc
|
@ -88,7 +88,7 @@ class CDNProxy:
|
||||||
|
|
||||||
def all_cdn(self):
|
def all_cdn(self):
|
||||||
"""获取cdn列表"""
|
"""获取cdn列表"""
|
||||||
with open('../cdn_list', 'r') as f:
|
with open('cdn_list', 'r') as f:
|
||||||
cdn = f.readlines()
|
cdn = f.readlines()
|
||||||
return cdn
|
return cdn
|
||||||
|
|
||||||
|
@ -101,6 +101,9 @@ class CDNProxy:
|
||||||
print(cdn_ip[0])
|
print(cdn_ip[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cdn = CDNProxy()
|
cdn = CDNProxy()
|
||||||
cdn.get_cdn_list()
|
cdn.get_cdn_list()
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
---
|
---
|
||||||
|
# 配置文件请严格遵循yaml语法格式,yaml学习地址 https://ansible-tran.readthedocs.io/en/latest/docs/YAMLSyntax.html
|
||||||
set:
|
set:
|
||||||
# 出发日期,格式ex:2018-01-06
|
# 出发日期(list),格式ex:2018-01-06
|
||||||
station_dates:
|
station_dates:
|
||||||
- "2018-09-05"
|
- "2018-09-05"
|
||||||
|
|
||||||
# 过滤车次,格式ex:- "G1353" - "G1329"
|
# 过滤车次(list),格式ex:- "G1353" - "G1329"
|
||||||
station_trains:
|
station_trains:
|
||||||
- "G6504"
|
- "G6504"
|
||||||
|
|
||||||
|
@ -14,23 +15,21 @@ set:
|
||||||
# 到达城市 比如深圳北,就填深圳就搜得到
|
# 到达城市 比如深圳北,就填深圳就搜得到
|
||||||
to_station: "广州"
|
to_station: "广州"
|
||||||
|
|
||||||
# 座位 多个座位ex: - "二等座" - "一等座"
|
# 座位(list) 多个座位ex: - "二等座" - "一等座"
|
||||||
set_type:
|
set_type:
|
||||||
- "二等座"
|
- "二等座"
|
||||||
|
|
||||||
# 余票不足是否自动提交,目前应该没什么卵用
|
# 余票不足是否自动提交,目前应该没什么卵用
|
||||||
is_more_ticket: True
|
is_more_ticket: True
|
||||||
|
|
||||||
# 乘车人 多个乘车人ex: - "张三" - "李四"
|
# 乘车人(list) 多个乘车人ex: - "张三" - "李四"
|
||||||
ticke_peoples:
|
ticke_peoples:
|
||||||
- ""
|
- ""
|
||||||
# 12306登录账号
|
# 12306登录账号(list)
|
||||||
12306account:
|
12306account:
|
||||||
- user: ""
|
- user: ""
|
||||||
- pwd: ""
|
- pwd: ""
|
||||||
|
|
||||||
select_refresh_interval: 1
|
|
||||||
|
|
||||||
# 加入小黑屋时间,此功能为了防止僵尸票导致一直下单不成功错过正常的票
|
# 加入小黑屋时间,此功能为了防止僵尸票导致一直下单不成功错过正常的票
|
||||||
ticket_black_list_time: 5
|
ticket_black_list_time: 5
|
||||||
|
|
||||||
|
@ -66,11 +65,11 @@ email_conf:
|
||||||
password: ""
|
password: ""
|
||||||
host: "smtp.qq.com"
|
host: "smtp.qq.com"
|
||||||
|
|
||||||
# 是否开启cdn查询,可以更快的检测飘飘 1为开启,2为关闭
|
# 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭
|
||||||
is_cdn: 2
|
is_cdn: 2
|
||||||
|
|
||||||
# 下单接口分为两种,1 为快速下单,2 是普通下单
|
# 下单接口分为两种,1 为快速下单,2 是普通下单
|
||||||
order_type: 1
|
order_type: 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
#!/bin/env python
|
|
||||||
# -*- coding=utf-8 -*-
|
# -*- coding=utf-8 -*-
|
||||||
import copy
|
|
||||||
import random
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import socket
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
from PIL import Image
|
|
||||||
from damatuCode.damatuWeb import DamatuApi
|
from damatuCode.damatuWeb import DamatuApi
|
||||||
from damatuCode.ruokuai import RClient
|
|
||||||
from inter.GetPassCodeNewOrderAndLogin import getPassCodeNewOrderAndLogin
|
from inter.GetPassCodeNewOrderAndLogin import getPassCodeNewOrderAndLogin
|
||||||
from inter.GetRandCode import getRandCode
|
from inter.GetRandCode import getRandCode
|
||||||
from myException.UserPasswordException import UserPasswordException
|
from myException.UserPasswordException import UserPasswordException
|
||||||
|
|
|
@ -3,8 +3,11 @@ import datetime
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import wrapcache
|
import wrapcache
|
||||||
|
|
||||||
|
from agency.cdn_utils import CDNProxy
|
||||||
from config import urlConf
|
from config import urlConf
|
||||||
from config.TicketEnmu import ticket
|
from config.TicketEnmu import ticket
|
||||||
from config.ticketConf import _get_yaml
|
from config.ticketConf import _get_yaml
|
||||||
|
@ -33,7 +36,7 @@ class select:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.from_station, self.to_station, self.station_dates, self._station_seat, self.is_more_ticket, \
|
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.ticke_peoples, self.station_trains, self.ticket_black_list_time, \
|
||||||
self.order_type = self.get_ticket_info()
|
self.order_type = self.get_ticket_info()
|
||||||
self.is_auto_code = _get_yaml()["is_auto_code"]
|
self.is_auto_code = _get_yaml()["is_auto_code"]
|
||||||
self.auto_code_type = _get_yaml()["auto_code_type"]
|
self.auto_code_type = _get_yaml()["auto_code_type"]
|
||||||
|
@ -57,12 +60,11 @@ class select:
|
||||||
set_type = ticket_info_config["set"]["set_type"]
|
set_type = ticket_info_config["set"]["set_type"]
|
||||||
is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
|
is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
|
||||||
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
|
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
|
||||||
select_refresh_interval = ticket_info_config["select_refresh_interval"]
|
|
||||||
station_trains = ticket_info_config["set"]["station_trains"]
|
station_trains = ticket_info_config["set"]["station_trains"]
|
||||||
ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
|
ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
|
||||||
order_type = ticket_info_config["order_type"]
|
order_type = ticket_info_config["order_type"]
|
||||||
print u"*" * 20
|
print u"*" * 20
|
||||||
print u"12306刷票小助手,最后更新于2018.2.28,请勿作为商业用途,交流群号:286271084"
|
print u"12306刷票小助手,最后更新于2018.8.31,请勿作为商业用途,交流群号:286271084"
|
||||||
print u"如果有好的margin,请联系作者,表示非常感激\n"
|
print u"如果有好的margin,请联系作者,表示非常感激\n"
|
||||||
print u"当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n" \
|
print u"当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n" \
|
||||||
u"刷新间隔:随机(1-4S)\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n 下单接口:{9}\n".format \
|
u"刷新间隔:随机(1-4S)\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n 下单接口:{9}\n".format \
|
||||||
|
@ -73,13 +75,12 @@ class select:
|
||||||
",".join(set_type),
|
",".join(set_type),
|
||||||
is_more_ticket,
|
is_more_ticket,
|
||||||
",".join(ticke_peoples),
|
",".join(ticke_peoples),
|
||||||
select_refresh_interval,
|
|
||||||
",".join(station_trains),
|
",".join(station_trains),
|
||||||
ticket_black_list_time,
|
ticket_black_list_time,
|
||||||
order_type,
|
order_type,
|
||||||
)
|
)
|
||||||
print u"*" * 20
|
print u"*" * 20
|
||||||
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, select_refresh_interval, station_trains, ticket_black_list_time, order_type
|
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, station_trains, ticket_black_list_time, order_type
|
||||||
|
|
||||||
def station_table(self, from_station, to_station):
|
def station_table(self, from_station, to_station):
|
||||||
"""
|
"""
|
||||||
|
@ -108,13 +109,56 @@ class select:
|
||||||
else:
|
else:
|
||||||
self.login.go_login()
|
self.login.go_login()
|
||||||
|
|
||||||
|
def set_cdn(self):
|
||||||
|
"""
|
||||||
|
设置cdn
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
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)]
|
||||||
|
|
||||||
|
def cdn_req(self, cdn):
|
||||||
|
for i in range(len(cdn) - 1):
|
||||||
|
http = HTTPClient()
|
||||||
|
urls = self.urls["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 < 500:
|
||||||
|
print("加入cdn {0}".format(cdn[i].replace("\n", "")))
|
||||||
|
self.cdn_list.append(cdn[i].replace("\n", ""))
|
||||||
|
print(u"所有cdn解析完成...")
|
||||||
|
|
||||||
|
def cdn_certification(self):
|
||||||
|
"""
|
||||||
|
cdn 认证
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if self.is_cdn == 1:
|
||||||
|
CDN = CDNProxy()
|
||||||
|
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,))
|
||||||
|
t2 = threading.Thread(target=self.set_cdn, args=())
|
||||||
|
t.start()
|
||||||
|
t2.start()
|
||||||
|
else:
|
||||||
|
raise ticketConfigException(u"cdn列表为空,请先加载cdn")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
|
self.cdn_certification()
|
||||||
l = liftTicketInit(session=self)
|
l = liftTicketInit(session=self)
|
||||||
l.reqLiftTicketInit()
|
l.reqLiftTicketInit()
|
||||||
self.call_login()
|
self.call_login()
|
||||||
checkUser(self).sendCheckUser()
|
checkUser(self).sendCheckUser()
|
||||||
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)
|
||||||
num = 1
|
num = 0
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
num += 1
|
num += 1
|
||||||
|
@ -184,18 +228,16 @@ class select:
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
random_time = random.uniform(1, 4)
|
random_time = round(random.uniform(1, 4), 2)
|
||||||
time.sleep(round(random_time, 2))
|
time.sleep(random_time)
|
||||||
print u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num,
|
print u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num,
|
||||||
",".join(
|
",".join(
|
||||||
self.station_dates),
|
self.station_dates),
|
||||||
",".join(
|
",".join(
|
||||||
self.station_trains),
|
self.station_trains),
|
||||||
(
|
(datetime.datetime.now() - start_time).microseconds / 1000,
|
||||||
datetime.datetime.now() - start_time).microseconds / 1000,
|
|
||||||
self.httpClint.cdn,
|
self.httpClint.cdn,
|
||||||
len(
|
len(self.cdn_list),
|
||||||
self.cdn_list),
|
|
||||||
random_time)
|
random_time)
|
||||||
except PassengerUserException as e:
|
except PassengerUserException as e:
|
||||||
print e.message
|
print e.message
|
||||||
|
|
|
@ -18,5 +18,5 @@ def getPassCodeNewOrderAndLogin(session, imgType):
|
||||||
try:
|
try:
|
||||||
print(u"下载验证码成功")
|
print(u"下载验证码成功")
|
||||||
open(img_path, 'wb').write(result)
|
open(img_path, 'wb').write(result)
|
||||||
except OSError as e:
|
except OSError:
|
||||||
print (e)
|
print (u"验证码下载失败,可能ip被封,确认请手动请求: {0}".format(codeImgUrl))
|
||||||
|
|
|
@ -23,7 +23,7 @@ def getRandCode(is_auto_code, auto_code_type):
|
||||||
return codexy(Ofset=",".join(list(Result["Result"])), is_raw_input=False)
|
return codexy(Ofset=",".join(list(Result["Result"])), is_raw_input=False)
|
||||||
else:
|
else:
|
||||||
if "Error" in Result and Result["Error"]:
|
if "Error" in Result and Result["Error"]:
|
||||||
print Result["Error"]
|
print u"打码平台错误: {0}, 请登录打码平台查看-http://www.ruokuai.com/client/index?6726".format(Result["Error"])
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
img = Image.open('./tkcode')
|
img = Image.open('./tkcode')
|
||||||
|
@ -39,7 +39,14 @@ def codexy(Ofset=None, is_raw_input=True):
|
||||||
:return: str
|
:return: str
|
||||||
"""
|
"""
|
||||||
if is_raw_input:
|
if is_raw_input:
|
||||||
Ofset = raw_input(u"请输入验证码: ")
|
print(u"""
|
||||||
|
*****************
|
||||||
|
| 0 | 1 | 2 | 3 |
|
||||||
|
*****************
|
||||||
|
| 4 | 5 | 6 | 7 |
|
||||||
|
*****************
|
||||||
|
""")
|
||||||
|
Ofset = raw_input(u"按照上图提示输入对应的验证码: ")
|
||||||
Ofset = Ofset.replace(",", ",")
|
Ofset = Ofset.replace(",", ",")
|
||||||
select = Ofset.split(',')
|
select = Ofset.split(',')
|
||||||
post = []
|
post = []
|
||||||
|
|
|
@ -49,7 +49,7 @@ class query:
|
||||||
station_ticket = self.session.httpClint.send(select_url)
|
station_ticket = self.session.httpClint.send(select_url)
|
||||||
value = station_ticket.get("data", "")
|
value = station_ticket.get("data", "")
|
||||||
if not value:
|
if not value:
|
||||||
print (u'{0}-{1} 车次坐席查询为空'.format(self.from_station, self.to_station))
|
print (u'{0}-{1} 车次坐席查询为空'.format(self.from_station_h, self.to_station_h))
|
||||||
else:
|
else:
|
||||||
result = value.get('result', [])
|
result = value.get('result', [])
|
||||||
if result:
|
if result:
|
||||||
|
@ -67,15 +67,12 @@ class query:
|
||||||
stationTrainCode = ticket_info[3]
|
stationTrainCode = ticket_info[3]
|
||||||
leftTicket = ticket_info[12]
|
leftTicket = ticket_info[12]
|
||||||
set_type = self._station_seat[j]
|
set_type = self._station_seat[j]
|
||||||
print (u'车次: {0} 始发车站: {1} 终点站: {2} {3}: {4}'.format(train_no,
|
print (u'车次: {0} 始发车站: {1} 终点站: {2} {3}: {4}'.format(ticket_info[3],
|
||||||
self.from_station_h,
|
self.from_station_h,
|
||||||
self.to_station_h,
|
self.to_station_h,
|
||||||
self._station_seat[j].encode(
|
self._station_seat[j].encode(
|
||||||
"utf8"),
|
"utf8"),
|
||||||
ticket_info[self.station_seat(
|
ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))]))
|
||||||
self._station_seat[
|
|
||||||
j].encode("utf8"))]
|
|
||||||
))
|
|
||||||
if wrapcache.get(train_no):
|
if wrapcache.get(train_no):
|
||||||
print(ticket.QUERY_IN_BLACK_LIST.format(train_no))
|
print(ticket.QUERY_IN_BLACK_LIST.format(train_no))
|
||||||
break
|
break
|
||||||
|
|
|
@ -113,7 +113,7 @@ class HTTPClient(object):
|
||||||
if is_logger:
|
if is_logger:
|
||||||
logger.log(
|
logger.log(
|
||||||
u"url: {0}\n入参: {1}\n请求方式: {2}\n".format(req_url, data, method, ))
|
u"url: {0}\n入参: {1}\n请求方式: {2}\n".format(req_url, data, method, ))
|
||||||
# self.setHeadersHost(urls["Host"])
|
self.setHeadersHost(urls["Host"])
|
||||||
if self.cdn:
|
if self.cdn:
|
||||||
url_host = self.cdn
|
url_host = self.cdn
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue