Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
janlyn06
12306
提交
bd5bebac
1
12306
项目概览
janlyn06
/
12306
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
12306
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bd5bebac
编写于
1月 12, 2018
作者:
W
wenxianping
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
跳出下单循环
上级
6a07fd47
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
147 addition
and
329 deletion
+147
-329
.idea/workspace.xml
.idea/workspace.xml
+90
-249
config/ticket_config.yaml
config/ticket_config.yaml
+3
-3
init/select_ticket_info.py
init/select_ticket_info.py
+54
-77
未找到文件。
.idea/workspace.xml
浏览文件 @
bd5bebac
此差异已折叠。
点击以展开。
config/ticket_config.yaml
浏览文件 @
bd5bebac
...
...
@@ -46,9 +46,9 @@ set:
-
"
彭淑杰"
-
"
金宏博"
12306count
:
# - uesr: "
13828728396
"
# - uesr: ""
# - pwd: "649823049lilymin"
-
uesr
:
"
931128603
@qq.com"
-
uesr
:
"
@qq.com"
-
pwd
:
"
QWERTY"
select_refresh_interval
:
0.1
...
...
@@ -58,7 +58,7 @@ is_aotu_code: False
#enable_proxy: False
damatu
:
uesr
:
"
wenxianping
"
uesr
:
"
"
pwd
:
"
wen1995"
...
...
init/select_ticket_info.py
浏览文件 @
bd5bebac
...
...
@@ -7,7 +7,6 @@ import threading
import
urllib
import
sys
import
time
import
Queue
from
collections
import
OrderedDict
from
config.ticketConf
import
_get_yaml
...
...
@@ -33,8 +32,6 @@ class select:
self
.
user_info
=
""
self
.
secretStr
=
""
self
.
ticket_black_list
=
dict
()
self
.
submitQueue
=
Queue
.
Queue
(
5
)
self
.
ticket_skip_time
=
dict
()
def
get_ticket_info
(
self
):
"""
...
...
@@ -53,7 +50,7 @@ class select:
expect_refresh_interval
=
ticket_info_config
[
"expect_refresh_interval"
]
ticket_black_list_time
=
ticket_info_config
[
"ticket_black_list_time"
]
print
"*"
*
20
print
"当前配置:出发站:{0}
\n
到达站:{1}
\n
乘车日期:{2}
\n
坐席:{3}
\n
是否有票自动提交:{4}
\n
乘车人:{5}
\n
刷新间隔:{6}
\n
候选购买车次:{7}
\n
未开始刷票间隔时间:{8}
\n
僵尸票关小黑屋时长:{9}"
.
format
\
print
"当前配置:出发站:{0}
\n
到达站:{1}
\n
乘车日期:{2}
\n
坐席:{3}
\n
是否有票自动提交:{4}
\n
乘车人:{5}
\n
刷新间隔:{6}
\n
候选购买车次:{7}
\n
未开始刷票间隔时间:{8}
\n
僵尸票关小黑屋时长:{9}
\n
"
.
format
\
(
from_station
,
to_station
,
...
...
@@ -234,13 +231,15 @@ class select:
if
self
.
ticket_black_list
.
has_key
(
train_no
)
and
(
datetime
.
datetime
.
now
()
-
self
.
ticket_black_list
[
train_no
]).
seconds
/
60
<
int
(
self
.
ticket_black_list_time
):
print
(
"该车次{} 正在被关小黑屋,跳过此车次"
.
format
(
train_no
))
break
if
self
.
ticket_skip_time
.
has_key
(
train_no
)
and
(
datetime
.
datetime
.
now
()
-
self
.
ticket_skip_time
[
train_no
]).
seconds
<
10
:
# 判断离上次车次订票时间,如果间隔太小,则跳过,如果想不停地疯狂提交,那请设置99999,就无等待了
break
else
:
self
.
submitQueue
.
put
({
"obj"
:
self
,
"train_no"
:
train_no
,
"seat"
:
self
.
_station_seat
[
j
].
encode
(
"utf8"
)})
print
(
'正在尝试提交订票...'
)
self
.
ticket_skip_time
[
train_no
]
=
datetime
.
datetime
.
now
()
if
self
.
check_user
():
self
.
submit_station
()
self
.
getPassengerTicketStr
(
self
.
_station_seat
[
j
].
encode
(
"utf8"
))
self
.
getRepeatSubmitToken
()
self
.
user_info
=
self
.
getPassengerDTOs
()
if
self
.
checkOrderInfo
(
train_no
,
self
.
_station_seat
[
j
].
encode
(
"utf8"
)):
break
else
:
pass
else
:
...
...
@@ -381,6 +380,7 @@ class select:
else
:
if
"errMsg"
in
checkOrderInfo
[
'data'
]
and
checkOrderInfo
[
'data'
][
"errMsg"
]:
print
checkOrderInfo
[
'data'
][
"errMsg"
]
else
:
print
checkOrderInfo
elif
'messages'
in
checkOrderInfo
and
checkOrderInfo
[
'messages'
]:
...
...
@@ -448,6 +448,7 @@ class select:
模拟提交订单是确认按钮,参数获取方法还是get_ticketInfoForPassengerForm 中获取
:return:
"""
passengerTicketStrList
,
oldPassengerStr
=
self
.
getPassengerTicketStrListAndOldPassengerStr
()
checkQueueOrderUrl
=
"https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue"
data
=
{
...
...
@@ -546,7 +547,7 @@ class select:
elif
"messages"
in
queryOrderWaitTimeResult
and
queryOrderWaitTimeResult
[
"messages"
]:
print
(
"排队等待失败: "
+
queryOrderWaitTimeResult
[
"messages"
])
else
:
print
(
"第{}
次
排队中,请耐心等待"
.
format
(
num
))
print
(
"第{}排队中,请耐心等待"
.
format
(
num
))
else
:
print
(
"排队中"
)
time
.
sleep
(
2
)
...
...
@@ -609,82 +610,58 @@ class select:
def
main
(
self
):
from_station
,
to_station
=
self
.
station_table
(
self
.
from_station
,
self
.
to_station
)
if
self
.
leftTicketLog
(
from_station
,
to_station
):
submitOrderConsumer
(
"daemon1"
,
self
.
submitQueue
).
start
()
num
=
1
runedTime
=
0
while
1
:
num
+=
1
sleepTime
=
self
.
select_refresh_interval
*
1000
-
runedTime
if
sleepTime
>
0
:
time
.
sleep
(
sleepTime
/
1000.0
)
if
time
.
strftime
(
'%H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
>
"23:00:00"
:
print
"12306休息时间,本程序自动停止,明天早上七点运行"
break
start_time
=
datetime
.
datetime
.
now
()
try
:
num
+=
1
time
.
sleep
(
self
.
select_refresh_interval
)
if
time
.
strftime
(
'%H:%M:%S'
,
time
.
localtime
(
time
.
time
()))
>
"23:00:00"
:
print
"12306休息时间,本程序自动停止,明天早上七点运行"
break
start_time
=
datetime
.
datetime
.
now
()
self
.
submitOrderRequest
(
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
)
except
PassengerUserException
as
e
:
print
e
.
message
break
except
ticketConfigException
as
e
:
print
e
.
message
break
except
ticketIsExitsException
as
e
:
print
e
.
message
break
except
ticketNumOutException
as
e
:
print
e
.
message
break
except
ValueError
as
e
:
if
e
.
message
==
"No JSON object could be decoded"
:
print
(
"12306接口无响应,正在重试"
)
else
:
print
(
e
.
message
)
runedTime
=
(
datetime
.
datetime
.
now
()
-
start_time
).
microseconds
/
1000
print
"正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 代理设置 无 总耗时{3}ms"
.
format
(
num
,
self
.
station_date
,
","
.
join
(
self
.
station_trains
),
runedTime
)
class
selectProducer
(
threading
.
Thread
):
"""刷票队列"""
def
__init__
(
self
,
t_name
,
data
):
self
.
t_name
=
t_name
self
.
data
=
data
threading
.
Thread
.
__init__
(
self
,
name
=
self
.
t_name
)
print
"{0} 正在运行"
.
format
(
self
.
t_name
)
def
run
(
self
):
self
.
worker
(
self
.
data
)
def
worker
(
self
,
data
):
obj
=
data
[
'obj'
]
try
:
if
obj
.
check_user
():
obj
.
submit_station
()
obj
.
getPassengerTicketStr
(
data
[
'seat'
])
obj
.
getRepeatSubmitToken
()
obj
.
user_info
=
obj
.
getPassengerDTOs
()
if
obj
.
checkOrderInfo
(
data
[
'train_no'
],
data
[
'seat'
]):
return
obj
.
submitQueue
.
task_done
()
except
PassengerUserException
as
e
:
print
e
.
message
except
ticketConfigException
as
e
:
print
e
.
message
except
ticketIsExitsException
as
e
:
print
e
.
message
except
ticketNumOutException
as
e
:
print
e
.
message
except
ValueError
as
e
:
if
e
.
message
==
"No JSON object could be decoded"
:
print
(
"12306接口无响应,正在重试"
)
else
:
print
(
e
.
message
)
print
(
"{0} 线程运行结束"
.
format
(
self
.
t_name
))
class
submitOrderConsumer
(
threading
.
Thread
):
"""订单队列"""
def
__init__
(
self
,
t_name
,
queue
):
threading
.
Thread
.
__init__
(
self
,
name
=
t_name
)
self
.
data
=
queue
print
"{0} 正在运行"
.
format
(
t_name
)
def
run
(
self
):
while
1
:
if
not
self
.
data
.
empty
():
taskData
=
self
.
data
.
get
()
selectProducer
(
taskData
[
'train_no'
]
+
str
(
random
.
random
()),
taskData
).
start
()
else
:
time
.
sleep
(
1.5
)
except
KeyError
as
e
:
print
(
e
.
message
)
# class selectProducer(threading.Thread):
# """刷票队列"""
# def __init__(self, t_name, queue):
# threading.Thread.__init__(self, name=t_name)
# self.data = queue
# print "{0} 正在运行".format(t_name)
#
# def run(self):
# pass
#
#
# class submitOrderConsumer(threading.Thread):
# """订单队列"""
# def __init__(self, t_name, queue):
# threading.Thread.__init__(self, name=t_name)
# self.data = queue
# print "{0} 正在运行".format(t_name)
#
# def run(self):
# pass
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录