mirror of https://github.com/testerSunshine/12306
优化查询速度
parent
3c9bf71b0f
commit
34dbcdb97a
|
@ -171,6 +171,24 @@ class select:
|
||||||
print("未查找到常用联系人")
|
print("未查找到常用联系人")
|
||||||
raise PassengerUserException("未查找到常用联系人,请先添加联系人在试试")
|
raise PassengerUserException("未查找到常用联系人,请先添加联系人在试试")
|
||||||
|
|
||||||
|
def leftTicketLog(self, from_station, to_station):
|
||||||
|
"""
|
||||||
|
模拟进入车次列表页
|
||||||
|
:param from_station:
|
||||||
|
:param to_station:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
leftTicketLogUrl = 'https://kyfw.12306.cn/otn/leftTicket/log?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT'.format(
|
||||||
|
self.station_date, from_station, to_station)
|
||||||
|
leftTicketLog = json.loads(myurllib2.get(leftTicketLogUrl), encoding='utf-8')
|
||||||
|
if "status" in leftTicketLog and leftTicketLog["status"] is True:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if "message" in leftTicketLog and leftTicketLog["message"]:
|
||||||
|
print leftTicketLog["message"]
|
||||||
|
elif "validateMessages" in leftTicketLog and leftTicketLog["validateMessages"]:
|
||||||
|
print leftTicketLog["validateMessages"]
|
||||||
|
|
||||||
def submitOrderRequest(self, from_station, to_station):
|
def submitOrderRequest(self, from_station, to_station):
|
||||||
"""
|
"""
|
||||||
提交车次信息
|
提交车次信息
|
||||||
|
@ -187,9 +205,6 @@ class select:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
select_url = 'https://kyfw.12306.cn/otn/leftTicket/queryZ?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT'.format(self.station_date, from_station, to_station)
|
select_url = 'https://kyfw.12306.cn/otn/leftTicket/queryZ?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT'.format(self.station_date, from_station, to_station)
|
||||||
leftTicketLogUrl = 'https://kyfw.12306.cn/otn/leftTicket/log?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT'.format(self.station_date, from_station, to_station)
|
|
||||||
leftTicketLog = json.loads(myurllib2.get(leftTicketLogUrl), encoding='utf-8')
|
|
||||||
if "status" in leftTicketLog and leftTicketLog["status"] is True:
|
|
||||||
station_ticket = json.loads(myurllib2.get(select_url), encoding='utf-8')
|
station_ticket = json.loads(myurllib2.get(select_url), encoding='utf-8')
|
||||||
value = station_ticket['data']
|
value = station_ticket['data']
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -206,7 +221,7 @@ class select:
|
||||||
# tiket_values = [k for k in value['map'].values()]
|
# tiket_values = [k for k in value['map'].values()]
|
||||||
self.secretStr = ticket_info[0]
|
self.secretStr = ticket_info[0]
|
||||||
train_no = ticket_info[3]
|
train_no = ticket_info[3]
|
||||||
print ('车次: ' + train_no + ' 始发车站: ' + self.to_station + ' 终点站: ' +
|
print ('车次: ' + 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"))])
|
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 (self.ticket_black_list["train_no"] - datetime.datetime.now()).seconds/60 < self.ticket_black_list_time:
|
if self.ticket_black_list.has_key(train_no) and (self.ticket_black_list["train_no"] - datetime.datetime.now()).seconds/60 < self.ticket_black_list_time:
|
||||||
print("该车次{} 正在被关小黑屋,跳过此车次".format(train_no))
|
print("该车次{} 正在被关小黑屋,跳过此车次".format(train_no))
|
||||||
|
@ -230,11 +245,7 @@ class select:
|
||||||
time.sleep(self.expect_refresh_interval)
|
time.sleep(self.expect_refresh_interval)
|
||||||
else:
|
else:
|
||||||
raise ticketConfigException("车次配置信息有误,请检查")
|
raise ticketConfigException("车次配置信息有误,请检查")
|
||||||
else:
|
|
||||||
if "message" in leftTicketLog and leftTicketLog["message"]:
|
|
||||||
print leftTicketLog["message"]
|
|
||||||
elif "validateMessages" in leftTicketLog and leftTicketLog["validateMessages"]:
|
|
||||||
print leftTicketLog["validateMessages"]
|
|
||||||
|
|
||||||
def check_user(self):
|
def check_user(self):
|
||||||
"""
|
"""
|
||||||
|
@ -548,6 +559,7 @@ class select:
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
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):
|
||||||
num = 1
|
num = 1
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue