mirror of https://github.com/testerSunshine/12306
优化查询
parent
0cc85766a4
commit
43799d3b56
|
@ -6,8 +6,9 @@ import sys
|
||||||
import csv
|
import csv
|
||||||
import requests
|
import requests
|
||||||
from config import urlConf
|
from config import urlConf
|
||||||
reload(sys)
|
if sys.version_info.major == 2:
|
||||||
sys.setdefaultencoding('utf-8')
|
reload(sys)
|
||||||
|
sys.setdefaultencoding('utf-8')
|
||||||
|
|
||||||
|
|
||||||
class CDNProxy:
|
class CDNProxy:
|
||||||
|
@ -42,7 +43,7 @@ class CDNProxy:
|
||||||
city_re = re.compile(r"<li id=\"(\S+)\" class=\"PingListCent PingRLlist")
|
city_re = re.compile(r"<li id=\"(\S+)\" class=\"PingListCent PingRLlist")
|
||||||
self.city_list = re.findall(city_re, rep.content)
|
self.city_list = re.findall(city_re, rep.content)
|
||||||
if self.city_list:
|
if self.city_list:
|
||||||
print self.city_list
|
print(self.city_list)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
saleMinDelayDay = 0
|
saleMinDelayDay = 0
|
||||||
|
@ -25,7 +26,11 @@ seat_conf = {'商务座': 32,
|
||||||
'硬座': 29,
|
'硬座': 29,
|
||||||
'无座': 26,
|
'无座': 26,
|
||||||
}
|
}
|
||||||
seat_conf_2 = dict([(v,k) for (k,v) in seat_conf.iteritems()])
|
if sys.version_info.major == 2:
|
||||||
|
seat_conf_2 = dict([(v,k) for (k,v) in seat_conf.iteritems()])
|
||||||
|
else:
|
||||||
|
seat_conf_2 = dict([(v, k) for (k, v) in seat_conf.items()])
|
||||||
|
|
||||||
|
|
||||||
def getNowTimestamp():
|
def getNowTimestamp():
|
||||||
return time.time()
|
return time.time()
|
||||||
|
|
|
@ -13,4 +13,4 @@ def _get_yaml():
|
||||||
f = open(path)
|
f = open(path)
|
||||||
s = yaml.load(f)
|
s = yaml.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
return s
|
return s.decode() if isinstance(s, bytes) else s
|
|
@ -5,8 +5,7 @@ set:
|
||||||
# - 2018-01-06
|
# - 2018-01-06
|
||||||
# - 2018-01-07
|
# - 2018-01-07
|
||||||
station_dates:
|
station_dates:
|
||||||
- "2019-01-27"
|
- "2019-01-11"
|
||||||
- "2019-01-26"
|
|
||||||
|
|
||||||
# 是否根据时间范围 和 乘车类型 购票
|
# 是否根据时间范围 和 乘车类型 购票
|
||||||
# 否则将需要手动填写车次
|
# 否则将需要手动填写车次
|
||||||
|
@ -115,11 +114,14 @@ email_conf:
|
||||||
is_cdn: 1
|
is_cdn: 1
|
||||||
|
|
||||||
# 下单接口分为两种,1 为快速下单,2 是普通下单
|
# 下单接口分为两种,1 为快速下单,2 是普通下单
|
||||||
order_type: 2
|
order_type: 1
|
||||||
|
|
||||||
# 下单模式 1 为预售,整点刷新,刷新间隔0.1-0.5S, 然后会校验时间,比如12点的预售,那脚本就会在12.00整检票,刷新订单
|
# 下单模式 1 为预售,整点刷新,刷新间隔0.1-0.5S, 然后会校验时间,比如12点的预售,那脚本就会在12.00整检票,刷新订单
|
||||||
# 2 是捡漏,捡漏的刷新间隔时间为0.5-3秒,时间间隔长,不容易封ip
|
# 2 是捡漏,捡漏的刷新间隔时间为0.5-3秒,时间间隔长,不容易封ip
|
||||||
order_model: 1
|
order_model: 2
|
||||||
|
|
||||||
|
# 预售放票时间, 如果是捡漏模式,可以忽略此操作
|
||||||
|
open_time: '20:15:00'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,5 +52,5 @@ class RClient(object):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
rc = RClient('931128603', '',)
|
rc = RClient('931128603', '',)
|
||||||
im = open('tkcode', 'rb').read()
|
im = open('tkcode', 'rb').read()
|
||||||
print rc.rk_create(im, 6113)
|
print(rc.rk_create(im, 6113))
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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
|
||||||
from myException.balanceException import balanceException
|
from myException.balanceException import balanceException
|
||||||
from myUrllib import myurllib2
|
|
||||||
|
|
||||||
|
|
||||||
class GoLogin:
|
class GoLogin:
|
||||||
|
@ -127,15 +126,6 @@ class GoLogin:
|
||||||
self.getUserName(uamtk)
|
self.getUserName(uamtk)
|
||||||
break
|
break
|
||||||
|
|
||||||
def logout(self):
|
|
||||||
url = 'https://kyfw.12306.cn/otn/login/loginOut'
|
|
||||||
result = myurllib2.get(url)
|
|
||||||
if result:
|
|
||||||
print (u"已退出")
|
|
||||||
else:
|
|
||||||
print (u"退出失败")
|
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == "__main__":
|
# if __name__ == "__main__":
|
||||||
# # main()
|
# # main()
|
||||||
# # logout()
|
# # logout()
|
|
@ -29,9 +29,9 @@ from myException.ticketIsExitsException import ticketIsExitsException
|
||||||
from myException.ticketNumOutException import ticketNumOutException
|
from myException.ticketNumOutException import ticketNumOutException
|
||||||
from myUrllib.httpUtils import HTTPClient
|
from myUrllib.httpUtils import HTTPClient
|
||||||
from utils.timeUtil import time_to_minutes, minutes_to_time
|
from utils.timeUtil import time_to_minutes, minutes_to_time
|
||||||
|
if sys.version_info.major == 2:
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf-8')
|
sys.setdefaultencoding('utf-8')
|
||||||
|
|
||||||
|
|
||||||
class select:
|
class select:
|
||||||
|
@ -43,7 +43,7 @@ class select:
|
||||||
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.station_trains, self.ticket_black_list_time, \
|
self.ticke_peoples, self.station_trains, self.ticket_black_list_time, \
|
||||||
self.order_type, self.is_by_time, self.train_types, self.departure_time, \
|
self.order_type, self.is_by_time, self.train_types, self.departure_time, \
|
||||||
self.arrival_time, self.take_time, self.order_model = self.get_ticket_info()
|
self.arrival_time, self.take_time, self.order_model, self.open_time = 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"]
|
||||||
self.is_cdn = _get_yaml()["is_cdn"]
|
self.is_cdn = _get_yaml()["is_cdn"]
|
||||||
|
@ -82,17 +82,18 @@ class select:
|
||||||
|
|
||||||
# 下单模式
|
# 下单模式
|
||||||
order_model = ticket_info_config["order_model"]
|
order_model = ticket_info_config["order_model"]
|
||||||
|
open_time = ticket_info_config["open_time"]
|
||||||
|
|
||||||
print u"*" * 20
|
print(u"*" * 50)
|
||||||
print u"12306刷票小助手,最后更新于2019.01.02,请勿作为商业用途,交流群号:286271084(已满), 请加2群:649992274"
|
print(u"12306刷票小助手,最后更新于2019.01.02,请勿作为商业用途,交流群号:286271084(已满), 请加2群:649992274")
|
||||||
if is_by_time:
|
if is_by_time:
|
||||||
method_notie = u"购票方式:根据时间区间购票\n可接受最早出发时间:{0}\n可接受最晚抵达时间:{1}\n可接受最长旅途时间:{2}\n可接受列车类型:{3}\n" \
|
method_notie = u"购票方式:根据时间区间购票\n可接受最早出发时间:{0}\n可接受最晚抵达时间:{1}\n可接受最长旅途时间:{2}\n可接受列车类型:{3}\n" \
|
||||||
.format(minutes_to_time(departure_time), minutes_to_time(arrival_time), minutes_to_time(take_time),
|
.format(minutes_to_time(departure_time), minutes_to_time(arrival_time), minutes_to_time(take_time),
|
||||||
" , ".join(train_types))
|
" , ".join(train_types))
|
||||||
else:
|
else:
|
||||||
method_notie = u"购票方式:根据候选车次购买\n候选购买车次:{0}".format(",".join(station_trains))
|
method_notie = u"购票方式:根据候选车次购买\n候选购买车次:{0}".format(",".join(station_trains))
|
||||||
print u"当前配置:\n出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票优先提交:{4}\n乘车人:{5}\n" \
|
print (u"当前配置:\n出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票优先提交:{4}\n乘车人:{5}\n" \
|
||||||
u"刷新间隔:随机(1-3S)\n{6}\n僵尸票关小黑屋时长:{7}\n 下单接口:{8}\n 下单模式:{9}\n".format \
|
u"刷新间隔: 随机(1-3S)\n{6}\n僵尸票关小黑屋时长: {7}\n下单接口: {8}\n下单模式: {9}\n预售踩点时间:{10} ".format \
|
||||||
(
|
(
|
||||||
from_station,
|
from_station,
|
||||||
to_station,
|
to_station,
|
||||||
|
@ -103,12 +104,13 @@ class select:
|
||||||
method_notie,
|
method_notie,
|
||||||
ticket_black_list_time,
|
ticket_black_list_time,
|
||||||
order_type,
|
order_type,
|
||||||
order_model
|
order_model,
|
||||||
)
|
open_time,
|
||||||
print u"*" * 20
|
))
|
||||||
|
print (u"*" * 50)
|
||||||
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, station_trains, \
|
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, station_trains, \
|
||||||
ticket_black_list_time, order_type, is_by_time, train_types, departure_time, arrival_time, take_time, \
|
ticket_black_list_time, order_type, is_by_time, train_types, departure_time, arrival_time, take_time, \
|
||||||
order_model
|
order_model, open_time
|
||||||
|
|
||||||
def station_table(self, from_station, to_station):
|
def station_table(self, from_station, to_station):
|
||||||
"""
|
"""
|
||||||
|
@ -146,7 +148,7 @@ class select:
|
||||||
rep = http.send(urls)
|
rep = http.send(urls)
|
||||||
if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 500:
|
if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 500:
|
||||||
if cdn[i].replace("\n", "") not in self.cdn_list: # 如果有重复的cdn,则放弃加入
|
if cdn[i].replace("\n", "") not in self.cdn_list: # 如果有重复的cdn,则放弃加入
|
||||||
print("加入cdn {0}".format(cdn[i].replace("\n", "")))
|
print(u"加入cdn {0}".format(cdn[i].replace("\n", "")))
|
||||||
self.cdn_list.append(cdn[i].replace("\n", ""))
|
self.cdn_list.append(cdn[i].replace("\n", ""))
|
||||||
print(u"所有cdn解析完成...")
|
print(u"所有cdn解析完成...")
|
||||||
|
|
||||||
|
@ -180,7 +182,6 @@ class select:
|
||||||
check_user.sendCheckUser()
|
check_user.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 = 0
|
num = 0
|
||||||
# isAutoSynchroTime = False
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
num += 1
|
num += 1
|
||||||
|
@ -194,13 +195,14 @@ class select:
|
||||||
time.sleep((open_time - now).seconds)
|
time.sleep((open_time - now).seconds)
|
||||||
self.call_login()
|
self.call_login()
|
||||||
if self.order_model is 1:
|
if self.order_model is 1:
|
||||||
sleep_time_s = 0.1
|
sleep_time_s = 0.5
|
||||||
sleep_time_t = 0.5
|
sleep_time_t = 0.6
|
||||||
# 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案
|
# 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案
|
||||||
if now.strftime("%M:%S") == "29:55" or now.strftime("%M:%S") == "59:55":
|
while not now.strftime("%H:%M:%S") == self.open_time:
|
||||||
print(u"预售整点模式卡点中")
|
now = datetime.datetime.now()
|
||||||
time.sleep(5)
|
if now.strftime("%H:%M:%S") > self.open_time:
|
||||||
print(u"预售模式执行")
|
break
|
||||||
|
time.sleep(0.0001)
|
||||||
else:
|
else:
|
||||||
sleep_time_s = 0.5
|
sleep_time_s = 0.5
|
||||||
sleep_time_t = 3
|
sleep_time_t = 3
|
||||||
|
@ -275,19 +277,19 @@ class select:
|
||||||
random_time))
|
random_time))
|
||||||
time.sleep(random_time)
|
time.sleep(random_time)
|
||||||
except PassengerUserException as e:
|
except PassengerUserException as e:
|
||||||
print e.message
|
print(e.message)
|
||||||
break
|
break
|
||||||
except ticketConfigException as e:
|
except ticketConfigException as e:
|
||||||
print e.message
|
print(e.message)
|
||||||
break
|
break
|
||||||
except ticketIsExitsException as e:
|
except ticketIsExitsException as e:
|
||||||
print e.message
|
print(e.message)
|
||||||
break
|
break
|
||||||
except ticketNumOutException as e:
|
except ticketNumOutException as e:
|
||||||
print e.message
|
print(e.message)
|
||||||
break
|
break
|
||||||
except UserPasswordException as e:
|
except UserPasswordException as e:
|
||||||
print e.message
|
print(e.message)
|
||||||
break
|
break
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
if e.message == "No JSON object could be decoded":
|
if e.message == "No JSON object could be decoded":
|
||||||
|
|
|
@ -68,7 +68,7 @@ class checkOrderInfo:
|
||||||
self.passengerTicketStrList,
|
self.passengerTicketStrList,
|
||||||
)
|
)
|
||||||
QueueCount.sendGetQueueCount()
|
QueueCount.sendGetQueueCount()
|
||||||
elif "errMsg" in checkOrderInfoRep['data'] and checkOrderInfoRep['data']["errMsg"]:
|
elif "errMsg" in data and data["errMsg"]:
|
||||||
print checkOrderInfoRep['data']["errMsg"]
|
print(checkOrderInfoRep['data']["errMsg"])
|
||||||
elif 'messages' in checkOrderInfoRep and checkOrderInfoRep['messages']:
|
elif 'messages' in checkOrderInfoRep and checkOrderInfoRep['messages']:
|
||||||
print (checkOrderInfoRep['messages'][0])
|
print (checkOrderInfoRep['messages'][0])
|
|
@ -23,7 +23,7 @@ def getRandCode(is_auto_code, auto_code_type, result):
|
||||||
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 u"打码平台错误: {0}, 请登录打码平台查看-http://www.ruokuai.com/client/index?6726".format(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')
|
||||||
|
|
|
@ -117,7 +117,7 @@ class query:
|
||||||
start_time = ticket_info[8]
|
start_time = ticket_info[8]
|
||||||
arrival_time = ticket_info[9]
|
arrival_time = ticket_info[9]
|
||||||
distance_time = ticket_info[10]
|
distance_time = ticket_info[10]
|
||||||
print start_time, arrival_time, distance_time
|
print(start_time, arrival_time, distance_time)
|
||||||
seat = j
|
seat = j
|
||||||
try:
|
try:
|
||||||
ticket_num = int(ticket_info[j])
|
ticket_num = int(ticket_info[j])
|
||||||
|
@ -160,7 +160,7 @@ class query:
|
||||||
"status": True,
|
"status": True,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
print u"车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket)
|
print(u"车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket))
|
||||||
return {"code": ticket.FAIL_CODE, "status": False}
|
return {"code": ticket.FAIL_CODE, "status": False}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class queryOrderWaitTime:
|
||||||
raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format(
|
raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format(
|
||||||
data.get("orderId")))
|
data.get("orderId")))
|
||||||
elif data.get("msg", False):
|
elif data.get("msg", False):
|
||||||
print data.get("msg", "")
|
print(data.get("msg", ""))
|
||||||
break
|
break
|
||||||
elif data.get("waitTime", False):
|
elif data.get("waitTime", False):
|
||||||
print(ticket.WAIT_ORDER_CONTINUE.format(0 - data.get("waitTime", False)))
|
print(ticket.WAIT_ORDER_CONTINUE.format(0 - data.get("waitTime", False)))
|
||||||
|
@ -83,7 +83,7 @@ class queryOrderWaitTime:
|
||||||
queryMyOrderNoCompleteResult["data"]["orderCacheDTO"]["message"]["message"])
|
queryMyOrderNoCompleteResult["data"]["orderCacheDTO"]["message"]["message"])
|
||||||
else:
|
else:
|
||||||
if queryMyOrderNoCompleteResult.get("message", False):
|
if queryMyOrderNoCompleteResult.get("message", False):
|
||||||
print queryMyOrderNoCompleteResult.get("message", False)
|
print(queryMyOrderNoCompleteResult.get("message", False))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
# -*- coding=utf-8 -*-
|
|
||||||
import httplib
|
|
||||||
import ssl
|
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import sys
|
|
||||||
from cookielib import LWPCookieJar
|
|
||||||
|
|
||||||
reload(sys)
|
|
||||||
sys.setdefaultencoding('UTF8')
|
|
||||||
cookiejar = LWPCookieJar()
|
|
||||||
cookiesuppor = urllib2.HTTPCookieProcessor(cookiejar)
|
|
||||||
opener = urllib2.build_opener(cookiesuppor, urllib2.HTTPHandler)
|
|
||||||
urllib2.install_opener(opener)
|
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
|
||||||
|
|
||||||
|
|
||||||
def get(url):
|
|
||||||
try:
|
|
||||||
request = urllib2.Request(url=url)
|
|
||||||
request.add_header("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
|
|
||||||
request.add_header('X-Requested-With', 'xmlHttpRequest')
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
request.add_header('Referer', 'https://kyfw.12306.cn/otn/confirmPassenger/initDc')
|
|
||||||
request.add_header('Accept', '*/*')
|
|
||||||
result = urllib2.urlopen(request).read()
|
|
||||||
assert isinstance(result, object)
|
|
||||||
return result
|
|
||||||
except httplib.error as e:
|
|
||||||
print e
|
|
||||||
pass
|
|
||||||
except urllib2.URLError as e:
|
|
||||||
print e
|
|
||||||
pass
|
|
||||||
except urllib2.HTTPBasicAuthHandler, urllib2.HTTPError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def Post(url, data):
|
|
||||||
try:
|
|
||||||
request = urllib2.Request(url=url, data=urllib.urlencode(data))
|
|
||||||
# req.add_header('User-Agent', 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0')
|
|
||||||
# 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('X-Requested-With', 'xmlHttpRequest')
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
request.add_header('Referer', 'https://kyfw.12306.cn/otn/confirmPassenger/initDc')
|
|
||||||
request.add_header('Accept', '*/*')
|
|
||||||
# request.add_header('Accept-Encoding', 'gzip, deflate')
|
|
||||||
for i in range(3):
|
|
||||||
result = urllib2.urlopen(request).read()
|
|
||||||
if result:
|
|
||||||
return result
|
|
||||||
else:
|
|
||||||
print("返回结果为空,正在第{0}重试".format(i))
|
|
||||||
except httplib.error as e:
|
|
||||||
return e
|
|
||||||
except urllib2.URLError as e:
|
|
||||||
return e
|
|
||||||
except urllib2.HTTPBasicAuthHandler, urllib2.HTTPError:
|
|
||||||
return ('error')
|
|
Loading…
Reference in New Issue