Merge pull request #51 from x-falcon/master

添加根据时间区间购票功能
pull/66/head
wenxianping 6 years ago committed by GitHub
commit f5126849a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,16 @@ RS_TIMEOUT = 1
RS_JSON_ERROR = 2
RS_OTHER_ERROR = 3
seat_conf = {'商务座': 32,
'一等座': 31,
'二等座': 30,
'特等座': 25,
'软卧': 23,
'硬卧': 28,
'硬座': 29,
'无座': 26,
}
seat_conf_2 = dict([(v,k) for (k,v) in seat_conf.iteritems()])
def getNowTimestamp():
return time.time()

@ -5,13 +5,32 @@ set:
# - 2018-01-06
# - 2018-01-07
station_dates:
- "2018-09-28"
- "2018-09-28"
# 是否根据时间范围 和 乘车类型 购票
# 否则将需要手动填写车次
is_by_time: False
# 列车类型: 高铁 G 动车 D 其它火车 O
train_types: [G,D,O]
# 可接受最早出发时间 格式ex
# departure_time: "8:00"
departure_time: "00:00"
# 可接受最晚抵达时间 格式ex
# arrival_time: "16:00"
arrival_time: "24:00"
# 可接受最长旅途时间 格式ex
# take_time: "24:00"
take_time: "24:00"
# 过滤车次(list)格式ex
# - "G1353"
# - "G1329"
station_trains:
- ""
- ""
# 出发城市,比如深圳北,就填深圳就搜得到
@ -24,7 +43,7 @@ set:
# - "二等座"
# - "一等座"
set_type:
- ""
- ""
# 当余票小于乘车人,如果选择优先提交,则删减联系人和余票数一致在提交
is_more_ticket: False
@ -33,11 +52,11 @@ set:
# - "张三"
# - "李四"
ticke_peoples:
- ""
- ""
# 12306登录账号(list)
12306account:
- user: ""
- pwd: ""
- user: ""
- pwd: ""
# 加入小黑屋时间,此功能为了防止僵尸票导致一直下单不成功错过正常的票
ticket_black_list_time: 5

@ -3,13 +3,15 @@ import datetime
import random
import socket
import sys
import threading
import time
import wrapcache
from agency.cdn_utils import CDNProxy
from config import urlConf
from config.TicketEnmu import ticket
from config.configCommon import seat_conf
from config.configCommon import seat_conf_2
from config.ticketConf import _get_yaml
from init.login import GoLogin
from inter.AutoSubmitOrderRequest import autoSubmitOrderRequest
@ -24,6 +26,7 @@ from myException.ticketConfigException import ticketConfigException
from myException.ticketIsExitsException import ticketIsExitsException
from myException.ticketNumOutException import ticketNumOutException
from myUrllib.httpUtils import HTTPClient
from utils.timeUtil import time_to_minutes,minutes_to_time
reload(sys)
sys.setdefaultencoding('utf-8')
@ -37,7 +40,9 @@ class select:
def __init__(self):
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.order_type = self.get_ticket_info()
self.order_type, self.is_by_time, self.train_types, self.departure_time, \
self.arrival_time, self.take_time = self.get_ticket_info()
self.is_auto_code = _get_yaml()["is_auto_code"]
self.auto_code_type = _get_yaml()["auto_code_type"]
self.is_cdn = _get_yaml()["is_cdn"]
@ -58,29 +63,43 @@ class select:
from_station = ticket_info_config["set"]["from_station"].encode("utf8")
to_station = ticket_info_config["set"]["to_station"].encode("utf8")
station_dates = ticket_info_config["set"]["station_dates"]
set_type = ticket_info_config["set"]["set_type"]
set_names = ticket_info_config["set"]["set_type"]
set_type = [seat_conf[x.encode("utf8")] for x in ticket_info_config["set"]["set_type"]]
is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
station_trains = ticket_info_config["set"]["station_trains"]
ticket_black_list_time = ticket_info_config["ticket_black_list_time"]
order_type = ticket_info_config["order_type"]
# by time
is_by_time = ticket_info_config["set"]["is_by_time"]
train_types = ticket_info_config["set"]["train_types"]
departure_time = time_to_minutes(ticket_info_config["set"]["departure_time"])
arrival_time = time_to_minutes(ticket_info_config["set"]["arrival_time"])
take_time = time_to_minutes(ticket_info_config["set"]["take_time"])
print u"*" * 20
print u"12306刷票小助手最后更新于2018.9.21请勿作为商业用途交流群号286271084"
if is_by_time:
method_notie="购票方式:根据时间区间购票\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)," , ".join(train_types))
else:
method_notie="购票方式:根据候选车次购买\n候选购买车次:{0}".format(",".join(station_trains))
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".format \
u"刷新间隔:随机(1-3S)\n{6}\n僵尸票关小黑屋时长:{7}\n 下单接口:{8}\n".format \
(
from_station,
to_station,
station_dates,
",".join(set_type),
",".join(set_names),
is_more_ticket,
",".join(ticke_peoples),
",".join(station_trains),
method_notie,
ticket_black_list_time,
order_type,
)
print u"*" * 20
return from_station, to_station, station_dates, set_type, is_more_ticket, ticke_peoples, 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, is_by_time, train_types, departure_time, arrival_time, take_time
def station_table(self, from_station, to_station):
"""
@ -155,13 +174,14 @@ class select:
l = liftTicketInit(self)
l.reqLiftTicketInit()
self.call_login()
checkUser(self).sendCheckUser()
check_user = checkUser(self)
check_user.sendCheckUser()
from_station, to_station = self.station_table(self.from_station, self.to_station)
num = 0
while 1:
try:
num += 1
checkUser(self).sendCheckUser()
check_user.sendCheckUser()
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00" or time.strftime('%H:%M:%S',
time.localtime(
time.time())) < "06:00:00":
@ -200,7 +220,8 @@ class select:
print(ticket.QUEUE_WARNING_MSG.format(train_no))
else:
# 获取联系人
s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, set_type=seat, is_more_ticket_num=is_more_ticket_num)
s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, set_type=seat_conf_2[seat],
is_more_ticket_num=is_more_ticket_num)
getPassengerDTOsResult = s.getPassengerTicketStrListAndOldPassengerStr()
if getPassengerDTOsResult.get("status", False):
self.passengerTicketStrList = getPassengerDTOsResult.get("passengerTicketStrList", "")

@ -8,7 +8,8 @@ import wrapcache
from config import urlConf
from config.TicketEnmu import ticket
from myUrllib.httpUtils import HTTPClient
from config.configCommon import seat_conf_2
from utils.timeUtil import time_to_minutes
class query:
"""
@ -30,6 +31,14 @@ class query:
self.ticket_black_list = dict()
self.ticke_peoples_num = ticke_peoples_num
#by time
self.is_by_time = session.is_by_time
self.train_types = session.train_types
self.departure_time = session.departure_time
self.arrival_time = session.arrival_time
self.take_time = session.take_time
@classmethod
def station_seat(self, index):
"""
获取车票对应坐席
@ -46,6 +55,25 @@ class query:
}
return seat[index]
def check_time_interval(self,ticket_info):
return self.departure_time <= time_to_minutes(ticket_info[8]) and \
time_to_minutes(ticket_info[9]) <= self.arrival_time and \
time_to_minutes(ticket_info[10]) <= self.take_time
def check_train_types(self,train):
train_type = train[0]
if train_type!="G" and train_type!="D":train_type="O"
if train_type in self.train_types:
return True
else:
return False
def check_is_need_train(self,ticket_info):
if self.is_by_time:
return self.check_train_types(ticket_info[3]) and self.check_time_interval(ticket_info)
else:
return ticket_info[3] in self.station_trains
def sendQuery(self):
"""
查询
@ -64,9 +92,9 @@ class query:
for i in value['result']:
ticket_info = i.split('|')
if ticket_info[11] == "Y" and ticket_info[1].encode("utf8") == "预订": # 筛选未在开始时间内的车次
for j in xrange(len(self._station_seat)):
is_ticket_pass = ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))]
if is_ticket_pass != '' and is_ticket_pass != '' and ticket_info[3] in self.station_trains and is_ticket_pass != '*': # 过滤有效目标车次
for j in self._station_seat:
is_ticket_pass = ticket_info[j]
if is_ticket_pass != '' and is_ticket_pass != '' and is_ticket_pass != '*' and self.check_is_need_train(ticket_info): # 过滤有效目标车次
secretStr = ticket_info[0]
train_no = ticket_info[2]
query_from_station_name = ticket_info[6]
@ -74,15 +102,19 @@ class query:
train_location = ticket_info[15]
stationTrainCode = ticket_info[3]
leftTicket = ticket_info[12]
seat = self._station_seat[j].encode("utf8")
start_time=ticket_info[8]
arrival_time=ticket_info[9]
distance_time=ticket_info[10]
print start_time,arrival_time,distance_time
seat = j
try:
ticket_num = int(ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))])
ticket_num = int(ticket_info[j])
except ValueError:
ticket_num = ""
print (u'车次: {0} 始发车站: {1} 终点站: {2} {3}: {4}'.format(ticket_info[3],
self.from_station_h,
self.to_station_h,
self._station_seat[j].encode("utf8"),
seat_conf_2[j],
ticket_num))
if wrapcache.get(train_no):
print(ticket.QUERY_IN_BLACK_LIST.format(train_no))

@ -0,0 +1,14 @@
def time_to_minutes(time_str):
s = time_str.split(":")
a = int(s[0]) * 60 + int(s[1])
return a
def minutes_to_time(minutes):
m = minutes % 60
if m<10:
return str(minutes / 60) + ":" + str("0"+str(m))
else:
return str(minutes / 60) + ":" + str(m)
Loading…
Cancel
Save