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
35c45bbe
Commit
35c45bbe
authored
Jan 22, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化错误提示
parent
f781c353
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
7 deletions
+8
-7
request.py
py12306/helpers/request.py
+5
-2
query_log.py
py12306/log/query_log.py
+2
-2
job.py
py12306/query/job.py
+1
-3
No files found.
py12306/helpers/request.py
View file @
35c45bbe
...
@@ -53,14 +53,17 @@ class Request(HTMLSession):
...
@@ -53,14 +53,17 @@ class Request(HTMLSession):
def
request
(
self
,
*
args
,
**
kwargs
):
# 拦截所有错误
def
request
(
self
,
*
args
,
**
kwargs
):
# 拦截所有错误
try
:
try
:
return
super
()
.
request
(
*
args
,
**
kwargs
)
response
=
super
()
.
request
(
*
args
,
**
kwargs
)
return
response
except
RequestException
as
e
:
except
RequestException
as
e
:
from
py12306.log.common_log
import
CommonLog
if
e
.
response
:
if
e
.
response
:
response
=
e
.
response
response
=
e
.
response
else
:
else
:
response
=
HTMLResponse
(
HTMLSession
)
response
=
HTMLResponse
(
HTMLSession
)
response
.
status_code
=
500
#
response.status_code = 500
expand_class
(
response
,
'json'
,
Request
.
json
)
expand_class
(
response
,
'json'
,
Request
.
json
)
response
.
reason
=
response
.
reason
if
response
.
reason
else
CommonLog
.
MESSAGE_RESPONSE_EMPTY_ERROR
return
response
return
response
def
cdn_request
(
self
,
url
:
str
,
cdn
=
None
,
method
=
'GET'
,
**
kwargs
):
def
cdn_request
(
self
,
url
:
str
,
cdn
=
None
,
method
=
'GET'
,
**
kwargs
):
...
...
py12306/log/query_log.py
View file @
35c45bbe
...
@@ -170,8 +170,8 @@ class QueryLog(BaseLog):
...
@@ -170,8 +170,8 @@ class QueryLog(BaseLog):
return
self
return
self
@
classmethod
@
classmethod
def
add_query_time_log
(
cls
,
start
,
end
,
is_cdn
):
def
add_query_time_log
(
cls
,
time
,
is_cdn
):
return
cls
()
.
add_log
((
'*'
if
is_cdn
else
''
)
+
'耗时
%.2
f'
%
(
end
-
start
)
)
return
cls
()
.
add_log
((
'*'
if
is_cdn
else
''
)
+
'耗时
%.2
f'
%
time
)
@
classmethod
@
classmethod
def
add_stay_log
(
cls
,
second
):
def
add_stay_log
(
cls
,
second
):
...
...
py12306/query/job.py
View file @
35c45bbe
...
@@ -103,11 +103,9 @@ class Job:
...
@@ -103,11 +103,9 @@ class Job:
self
.
refresh_station
(
station
)
self
.
refresh_station
(
station
)
for
date
in
self
.
left_dates
:
for
date
in
self
.
left_dates
:
self
.
left_date
=
date
self
.
left_date
=
date
tmp_start_time
=
time
.
time
()
response
=
self
.
query_by_date
(
date
)
response
=
self
.
query_by_date
(
date
)
tmp_end_time
=
time
.
time
()
# 耗时
self
.
handle_response
(
response
)
self
.
handle_response
(
response
)
QueryLog
.
add_query_time_log
(
t
mp_start_time
,
tmp_end_time
,
is_cdn
=
self
.
is_cdn
)
QueryLog
.
add_query_time_log
(
t
ime
=
response
.
elapsed
.
total_seconds
()
,
is_cdn
=
self
.
is_cdn
)
if
not
self
.
is_alive
:
return
if
not
self
.
is_alive
:
return
self
.
safe_stay
()
self
.
safe_stay
()
if
is_main_thread
():
if
is_main_thread
():
...
...
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