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
69f1a84c
Commit
69f1a84c
authored
Jan 18, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 cdn 优化下单逻辑
parent
21b09224
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
14 additions
and
8 deletions
+14
-8
cdn.py
py12306/helpers/cdn.py
+2
-4
func.py
py12306/helpers/func.py
+1
-0
common_log.py
py12306/log/common_log.py
+1
-1
order.py
py12306/order/order.py
+8
-2
job.py
py12306/user/job.py
+1
-1
web.py
py12306/web/web.py
+1
-0
No files found.
py12306/helpers/cdn.py
View file @
69f1a84c
...
...
@@ -100,9 +100,7 @@ class Cdn:
if
self
.
last_check_at
:
self
.
last_check_at
=
str_to_time
(
self
.
last_check_at
)
self
.
available_items
=
result
.
get
(
'items'
,
[])
self
.
unavailable_items
=
result
.
get
(
'fail_items'
,
[])
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_CDN_RESTORE_SUCCESS
.
format
(
self
.
last_check_at
,
self
.
last_check_at
+
timedelta
(
seconds
=
self
.
check_keep_second
)))
.
flush
()
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_CDN_RESTORE_SUCCESS
.
format
(
self
.
last_check_at
))
.
flush
()
return
True
return
False
...
...
@@ -219,7 +217,7 @@ class Cdn:
@
classmethod
def
get_cdn
(
cls
):
self
=
cls
()
if
self
.
is_ready
:
if
self
.
is_ready
and
self
.
available_items
:
return
random
.
choice
(
self
.
available_items
)
return
None
...
...
py12306/helpers/func.py
View file @
69f1a84c
# -*- coding: utf-8 -*-
import
datetime
import
hashlib
import
json
...
...
py12306/log/common_log.py
View file @
69f1a84c
...
...
@@ -51,7 +51,7 @@ class CommonLog(BaseLog):
MESSAGE_CDN_START_TO_CHECK
=
'正在筛选 {} 个 CDN...'
MESSAGE_CDN_START_TO_RECHECK
=
'正在重新筛选 {} 个 CDN...当前时间 {}
\n
'
MESSAGE_CDN_RESTORE_SUCCESS
=
'CDN 恢复成功,上次检测 {}
,下次检测 {}
\n
'
MESSAGE_CDN_RESTORE_SUCCESS
=
'CDN 恢复成功,上次检测 {}
\n
'
MESSAGE_CDN_CHECKED_SUCCESS
=
'# CDN 检测完成,可用 CDN {} #
\n
'
MESSAGE_CDN_CLOSED
=
'# CDN 已关闭 #'
...
...
py12306/order/order.py
View file @
69f1a84c
...
...
@@ -58,7 +58,11 @@ class Order:
return
self
.
normal_order
()
def
normal_order
(
self
):
if
not
self
.
submit_order_request
():
return
order_request_res
=
self
.
submit_order_request
()
if
order_request_res
==
-
1
:
return
self
.
order_did_success
()
elif
not
order_request_res
:
return
if
not
self
.
user_ins
.
request_init_dc_page
():
return
if
not
self
.
check_order_info
():
return
if
not
self
.
get_queue_count
():
return
...
...
@@ -75,6 +79,7 @@ class Order:
OrderLog
.
notification
(
OrderLog
.
MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE
,
OrderLog
.
MESSAGE_ORDER_SUCCESS_NOTIFICATION_CONTENT
)
self
.
send_notification
()
return
True
def
send_notification
(
self
):
# num = 0 # 通知次数
...
...
@@ -117,6 +122,7 @@ class Order:
# sleep(self.notification_interval)
OrderLog
.
add_quick_log
(
OrderLog
.
MESSAGE_JOB_CLOSED
)
.
flush
()
return
True
def
submit_order_request
(
self
):
data
=
{
...
...
@@ -136,7 +142,7 @@ class Order:
else
:
if
(
str
(
result
.
get
(
'messages'
,
''
))
.
find
(
'未处理'
)
>=
0
):
# 未处理订单
self
.
order_id
=
0
# 需要拿到订单号 TODO
return
self
.
order_did_success
()
return
-
1
OrderLog
.
add_quick_log
(
OrderLog
.
MESSAGE_SUBMIT_ORDER_REQUEST_FAIL
.
format
(
result
.
get
(
'messages'
,
CommonLog
.
MESSAGE_RESPONSE_EMPTY_ERROR
)))
.
flush
()
...
...
py12306/user/job.py
View file @
69f1a84c
...
...
@@ -306,7 +306,7 @@ class UserJob:
if
result
.
get
(
'data.normal_passengers'
):
self
.
passengers
=
result
.
get
(
'data.normal_passengers'
)
# 将乘客写入到文件
with
open
(
Config
()
.
USER_PASSENGERS_FILE
%
self
.
user_name
,
'w'
)
as
f
:
with
open
(
Config
()
.
USER_PASSENGERS_FILE
%
self
.
user_name
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
json
.
dumps
(
self
.
passengers
,
indent
=
4
,
ensure_ascii
=
False
))
return
self
.
passengers
else
:
...
...
py12306/web/web.py
View file @
69f1a84c
# -*- coding: utf-8 -*-
import
json
import
logging
from
datetime
import
timedelta
...
...
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