Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
py12306
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
python
py12306
Commits
25049389
Commit
25049389
authored
Jan 13, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化程序流程
parent
7c62c1eb
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
11 deletions
+28
-11
app.py
py12306/app.py
+4
-4
event.py
py12306/helpers/event.py
+1
-0
common_log.py
py12306/log/common_log.py
+5
-0
query_log.py
py12306/log/query_log.py
+2
-2
order.py
py12306/order/order.py
+3
-1
job.py
py12306/query/job.py
+6
-2
job.py
py12306/user/job.py
+2
-2
web.py
py12306/web/web.py
+5
-0
No files found.
py12306/app.py
View file @
25049389
...
...
@@ -56,10 +56,10 @@ class App:
def
register_sign
(
self
):
is_windows
=
os
.
name
==
'nt'
if
is_windows
:
#
if is_windows:
signs
=
[
signal
.
SIGINT
,
signal
.
SIGTERM
]
else
:
signs
=
[
signal
.
SIGINT
,
signal
.
SIGHUP
,
signal
.
SIGTERM
]
#
else:
# signs = [signal.SIGINT, signal.SIGHUP, signal.SIGTERM] # SIGHUP 会导致终端退出,程序也退出,暂时去掉
for
sign
in
signs
:
signal
.
signal
(
sign
,
self
.
handler_exit
)
...
...
py12306/helpers/event.py
View file @
25049389
...
...
@@ -36,6 +36,7 @@ class Event():
for
job
in
query
.
jobs
:
if
job
.
account_key
==
data
.
get
(
'key'
):
create_thread_and_run
(
job
,
'check_passengers'
,
Const
.
IS_TEST
)
# 检查乘客信息 防止提交订单时才检查
stay_second
(
1
)
def
user_job_destroy
(
self
,
data
=
{},
callback
=
False
):
from
py12306.user.user
import
User
...
...
py12306/log/common_log.py
View file @
25049389
...
...
@@ -49,6 +49,9 @@ class CommonLog(BaseLog):
if
not
Const
.
IS_TEST
and
Config
()
.
OUT_PUT_LOG_TO_FILE_ENABLED
:
self
.
add_quick_log
()
self
.
add_quick_log
(
'日志已输出到文件中: {}'
.
format
(
Config
()
.
OUT_PUT_LOG_TO_FILE_PATH
))
if
Config
()
.
WEB_ENABLE
:
self
.
add_quick_log
()
self
.
add_quick_log
(
'WEB 管理页面已开启,请访问 主机地址 + 端口 {} 进行查看'
.
format
(
Config
()
.
WEB_PORT
))
self
.
add_quick_log
()
self
.
flush
(
file
=
False
,
publish
=
False
)
...
...
@@ -64,8 +67,10 @@ class CommonLog(BaseLog):
self
.
add_quick_log
(
'多线程查询: {}'
.
format
(
get_true_false_text
(
Config
()
.
QUERY_JOB_THREAD_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'语音验证码: {}'
.
format
(
get_true_false_text
(
Config
()
.
NOTIFICATION_BY_VOICE_CODE
,
enable
,
disable
)))
self
.
add_quick_log
(
'邮件通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
EMAIL_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'查询间隔: {} 秒'
.
format
(
Config
()
.
QUERY_INTERVAL
))
self
.
add_quick_log
(
'用户心跳检测间隔: {} 秒'
.
format
(
Config
()
.
USER_HEARTBEAT_INTERVAL
))
self
.
add_quick_log
(
'WEB 管理页面: {}'
.
format
(
get_true_false_text
(
Config
()
.
WEB_ENABLE
,
enable
,
disable
)))
if
Config
()
.
is_cluster_enabled
():
from
py12306.cluster.cluster
import
Cluster
self
.
add_quick_log
(
'分布式查询: {}'
.
format
(
get_true_false_text
(
Config
()
.
is_cluster_enabled
(),
enable
,
enable
)))
...
...
py12306/log/query_log.py
View file @
25049389
...
...
@@ -33,10 +33,10 @@ class QueryLog(BaseLog):
MESSAGE_SKIP_ORDER
=
'跳过本次请求,节点 {} 用户 {} 正在处理该订单
\n
'
MESSAGE_QUERY_JOB_BEING_DESTROY
=
'
当前
查询任务 {} 已结束
\n
'
MESSAGE_QUERY_JOB_BEING_DESTROY
=
'查询任务 {} 已结束
\n
'
MESSAGE_INIT_PASSENGERS_SUCCESS
=
'初始化乘客成功'
MESSAGE_CHECK_PASSENGERS
=
'正在验证乘客信息'
MESSAGE_CHECK_PASSENGERS
=
'
查询任务 {}
正在验证乘客信息'
MESSAGE_USER_IS_EMPTY_WHEN_DO_ORDER
=
'未配置自动下单账号,{} 秒后继续查询
\n
'
MESSAGE_ORDER_USER_IS_EMPTY
=
'未找到下单账号,{} 秒后继续查询'
...
...
py12306/order/order.py
View file @
25049389
...
...
@@ -302,8 +302,10 @@ class Order:
:return:
"""
self
.
current_queue_wait
=
self
.
max_queue_wait
self
.
queue_num
=
0
while
self
.
current_queue_wait
:
self
.
current_queue_wait
-=
self
.
wait_queue_interval
self
.
queue_num
+=
1
# TODO 取消超时订单,待优化
data
=
{
#
'random'
:
str
(
random
.
random
())[
2
:],
...
...
@@ -346,7 +348,7 @@ class Order:
result
.
get
(
'messages'
,
result
.
get
(
'validateMessages'
))))
.
flush
()
else
:
pass
OrderLog
.
add_quick_log
(
OrderLog
.
MESSAGE_QUERY_ORDER_WAIT_TIME_INFO
.
format
(
self
.
current_queue_wait
))
.
flush
()
OrderLog
.
add_quick_log
(
OrderLog
.
MESSAGE_QUERY_ORDER_WAIT_TIME_INFO
.
format
(
self
.
queue_num
))
.
flush
()
stay_second
(
self
.
wait_queue_interval
)
return
False
...
...
py12306/query/job.py
View file @
25049389
...
...
@@ -266,8 +266,12 @@ class Job:
def
check_passengers
(
self
):
if
not
self
.
passengers
:
QueryLog
.
add_quick_log
(
QueryLog
.
MESSAGE_CHECK_PASSENGERS
)
.
flush
()
self
.
set_passengers
(
User
.
get_passenger_for_members
(
self
.
members
,
self
.
account_key
))
QueryLog
.
add_quick_log
(
QueryLog
.
MESSAGE_CHECK_PASSENGERS
.
format
(
self
.
job_name
))
.
flush
()
passengers
=
User
.
get_passenger_for_members
(
self
.
members
,
self
.
account_key
)
if
passengers
:
self
.
set_passengers
(
passengers
)
else
:
# 退出当前查询任务
self
.
destroy
()
return
True
def
refresh_station
(
self
,
station
):
...
...
py12306/user/job.py
View file @
25049389
...
...
@@ -324,8 +324,8 @@ class UserJob:
passenger
=
array_dict_find_by_key_value
(
self
.
passengers
,
'passenger_name'
,
member
)
if
not
passenger
:
UserLog
.
add_quick_log
(
UserLog
.
MESSAGE_USER_PASSENGERS_IS_INVALID
.
format
(
self
.
user_name
,
member
))
.
flush
(
exit
=
True
)
# TODO 需要优化
UserLog
.
MESSAGE_USER_PASSENGERS_IS_INVALID
.
format
(
self
.
user_name
,
member
))
.
flush
(
)
return
False
new_member
=
{
'name'
:
passenger
.
get
(
'passenger_name'
),
'id_card'
:
passenger
.
get
(
'passenger_id_no'
),
...
...
py12306/web/web.py
View file @
25049389
import
json
import
logging
from
datetime
import
timedelta
from
flask
import
Flask
,
request
...
...
@@ -13,9 +14,13 @@ from py12306.helpers.func import *
class
Web
:
session
=
None
jwt
=
None
log
=
None
def
__init__
(
self
):
self
.
session
=
Flask
(
__name__
)
self
.
log
=
logging
.
getLogger
(
'werkzeug'
)
self
.
log
.
setLevel
(
logging
.
ERROR
)
self
.
register_blueprint
()
self
.
session
.
config
[
'JWT_SECRET_KEY'
]
=
'secret'
# 目前都是本地,暂不用放配置文件
self
.
session
.
config
[
'JWT_ACCESS_TOKEN_EXPIRES'
]
=
timedelta
(
seconds
=
60
*
60
*
24
*
7
)
# Token 超时时间 7 天
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment