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
c8988cd2
Commit
c8988cd2
authored
Jan 14, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加集群状态支持
parent
01cf6cca
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
82 additions
and
17 deletions
+82
-17
README.md
README.md
+32
-10
web.png
data/images/web.png
+0
-0
order_log.py
py12306/log/order_log.py
+1
-1
job.py
py12306/user/job.py
+5
-2
stat.py
py12306/web/handler/stat.py
+22
-0
user.py
py12306/web/handler/user.py
+3
-1
app.35e2fbd94557d71d1e2bfa0d4bb44d13.css
...6/web/static/css/app.35e2fbd94557d71d1e2bfa0d4bb44d13.css
+15
-0
index.html
py12306/web/static/index.html
+3
-3
app.7d7d65cccfbfa339beba.js
py12306/web/static/js/app.7d7d65cccfbfa339beba.js
+1
-0
No files found.
README.md
View file @
c8988cd2
...
...
@@ -16,7 +16,7 @@
-
[
x
]
Docker 支持
-
[
x
]
动态修改配置文件
-
[
x
]
邮件通知
-
[
]
Web 管理页面
-
[
x
]
Web 管理页面
-
[
]
微信消息通知
## 使用
...
...
@@ -100,16 +100,38 @@ docker run -d -v $(pwd):/config -v py12306:/data pjialin/py12306
```
当前目录会多一个 12306.log 的日志文件,
`tail -f 12306.log`
## Web 管理页面
目前支持用户和任务以及日志日志查看,更多功能后续会不断加入
**使用**
打开 Web 功能需要将配置中的
`WEB_ENABLE`
打开,启动程序后访问当前主机地址 + 端口号 (默认 8008) 即可,如 http://127.0.0.1:8008
## 更新
### 19-01-10
*
支持分布式集群
### 19-01-11
*
配置文件支持动态修改
### 19-01-12
*
新增免费打码
## 下单成功截图

-
19-01-10
支持分布式集群
-
19-01-11
配置文件支持动态修改
-
19-01-12
新增免费打码
-
19-01-14
新增 Web 页面支持
## 截图
### Web 管理页面

### 下单成功

### 关于防封
目前查询和登录操作是分开的,查询是不依赖用户是否登录,放在 A 云 T 云容易被限制 ip,建议在其它网络环境下运行
...
...
data/images/web.png
0 → 100644
View file @
c8988cd2
220 KB
py12306/log/order_log.py
View file @
c8988cd2
...
...
@@ -30,7 +30,7 @@ class OrderLog(BaseLog):
MESSAGE_QUERY_ORDER_WAIT_TIME_INFO
=
'第 {} 次排队,请耐心等待'
MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE
=
'车票购买成功!'
MESSAGE_ORDER_SUCCESS_NOTIFICATION_CONTENT
=
'请及时
器
登录12306,打开
\'
未完成订单
\'
,在30分钟内完成支付!'
MESSAGE_ORDER_SUCCESS_NOTIFICATION_CONTENT
=
'请及时登录12306,打开
\'
未完成订单
\'
,在30分钟内完成支付!'
MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_VOICE_CODE_START_SEND
=
'正在发送语音通知, 第 {} 次'
MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_VOICE_CODE_CONTENT
=
'你的车票 {} 到 {} 购买成功,请登录 12306 进行支付'
...
...
py12306/user/job.py
View file @
c8988cd2
...
...
@@ -29,6 +29,7 @@ class UserJob:
user_loaded
=
False
# 用户是否已加载成功
passengers
=
[]
retry_time
=
3
login_num
=
0
# 尝试登录次数
# Init page
global_repeat_submit_token
=
None
...
...
@@ -101,9 +102,9 @@ class UserJob:
return
self
.
last_heartbeat
def
set_last_heartbeat
(
self
):
def
set_last_heartbeat
(
self
,
time
=
None
):
if
Config
()
.
is_cluster_enabled
():
return
self
.
cluster
.
session
.
set
(
Cluster
.
KEY_USER_LAST_HEARTBEAT
,
time_int
())
return
self
.
cluster
.
session
.
set
(
Cluster
.
KEY_USER_LAST_HEARTBEAT
,
time
if
time
!=
None
else
time
_int
())
self
.
last_heartbeat
=
time_int
()
# def init_cookies
...
...
@@ -184,6 +185,7 @@ class UserJob:
用户登录成功
:return:
"""
self
.
login_num
+=
1
self
.
welcome_user
()
self
.
save_user
()
self
.
get_user_info
()
...
...
@@ -222,6 +224,7 @@ class UserJob:
self
.
user_did_load
()
else
:
UserLog
.
add_quick_log
(
UserLog
.
MESSAGE_LOADED_USER_BUT_EXPIRED
)
.
flush
()
self
.
set_last_heartbeat
(
0
)
def
user_did_load
(
self
):
"""
...
...
py12306/web/handler/stat.py
View file @
c8988cd2
...
...
@@ -27,3 +27,25 @@ def dashboard():
'user_job_count'
:
user_job_count
,
'query_count'
:
query_count
})
@
stat
.
route
(
'/stat/cluster'
,
methods
=
[
'GET'
])
@
jwt_required
def
clusters
():
"""
节点统计
节点数量,主节点,子节点列表
:return:
"""
from
py12306.cluster.cluster
import
Cluster
nodes
=
Cluster
()
.
nodes
count
=
len
(
nodes
)
node_lists
=
list
(
nodes
)
master
=
[
key
for
key
,
val
in
nodes
.
items
()
if
int
(
val
)
==
Cluster
.
KEY_MASTER
]
master
=
master
[
0
]
if
master
else
''
return
jsonify
({
'master'
:
master
,
'count'
:
count
,
'node_lists'
:
', '
.
join
(
node_lists
)
})
py12306/web/handler/user.py
View file @
c8988cd2
...
...
@@ -49,6 +49,7 @@ def user_info():
}
return
jsonify
(
result
)
def
convert_job_to_info
(
job
:
UserJob
):
return
{
'key'
:
job
.
key
,
...
...
@@ -56,5 +57,6 @@ def convert_job_to_info(job: UserJob):
'name'
:
job
.
get_name
(),
'is_ready'
:
job
.
is_ready
,
'is_loaded'
:
job
.
user_loaded
,
# 是否成功加载 ready 是当前是否可用
'last_heartbeat'
:
timestamp_to_time
(
job
.
last_heartbeat
)
'last_heartbeat'
:
timestamp_to_time
(
job
.
last_heartbeat
),
'login_num'
:
job
.
login_num
}
py12306/web/static/css/app.35e2fbd94557d71d1e2bfa0d4bb44d13.css
0 → 100644
View file @
c8988cd2
This source diff could not be displayed because it is too large. You can
view the blob
instead.
py12306/web/static/index.html
View file @
c8988cd2
<!DOCTYPE html>
<html><head><meta
charset=
utf-8
><meta
name=
viewport
content=
"width=device-width,initial-scale=1"
><title>
py12306 购票助手
</title><link
href=
../../static/css/app.dfb5ffed622907edd7c5f81709f2b782.css
rel=
stylesheet
></head><body><script>
window
.
config
=
{
API_BASE_URL
:
'http://localhost:8080/'
,
}
</script><div
id=
app
></div><script
type=
text/javascript
src=
../../static/js/manifest.82f431004cf9bb6ad2cb.js
></script><script
type=
text/javascript
src=
../../static/js/vendor.aebd1de04bf90e88d9c7.js
></script><script
type=
text/javascript
src=
../../static/js/app.96ef02c9e5601eb5ebcb.js
></script></body></html>
\ No newline at end of file
<!DOCTYPE html>
<html><head><meta
charset=
utf-8
><meta
name=
viewport
content=
"width=device-width,initial-scale=1"
><title>
py12306 购票助手
</title><link
href=
../../static/css/app.35e2fbd94557d71d1e2bfa0d4bb44d13.css
rel=
stylesheet
></head><body><script>
window
.
config
=
{
API_BASE_URL
:
'http://localhost:8008/'
,
}
</script><div
id=
app
></div><script
type=
text/javascript
src=
../../static/js/manifest.82f431004cf9bb6ad2cb.js
></script><script
type=
text/javascript
src=
../../static/js/vendor.aebd1de04bf90e88d9c7.js
></script><script
type=
text/javascript
src=
../../static/js/app.7d7d65cccfbfa339beba.js
></script></body></html>
\ No newline at end of file
py12306/web/static/js/app.7d7d65cccfbfa339beba.js
0 → 100644
View file @
c8988cd2
This diff is collapsed.
Click to expand it.
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