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
cdedfa85
Commit
cdedfa85
authored
Feb 20, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加动态获取查询地址 #121
parent
484c5f2a
Pipeline
#17
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
api.py
py12306/helpers/api.py
+1
-0
job.py
py12306/query/job.py
+1
-1
query.py
py12306/query/query.py
+18
-0
No files found.
py12306/helpers/api.py
View file @
cdedfa85
...
@@ -39,6 +39,7 @@ API_INITDC_URL = BASE_URL_OF_12306 + '/otn/confirmPassenger/initDc' # 生成订
...
@@ -39,6 +39,7 @@ API_INITDC_URL = BASE_URL_OF_12306 + '/otn/confirmPassenger/initDc' # 生成订
API_GET_QUEUE_COUNT
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/getQueueCount'
API_GET_QUEUE_COUNT
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/getQueueCount'
API_CONFIRM_SINGLE_FOR_QUEUE
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/confirmSingleForQueue'
API_CONFIRM_SINGLE_FOR_QUEUE
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/confirmSingleForQueue'
API_QUERY_ORDER_WAIT_TIME
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/queryOrderWaitTime?{}'
# 排队查询
API_QUERY_ORDER_WAIT_TIME
=
BASE_URL_OF_12306
+
'/otn/confirmPassenger/queryOrderWaitTime?{}'
# 排队查询
API_QUERY_INIT_PAGE
=
BASE_URL_OF_12306
+
'/otn/leftTicket/init'
API_NOTIFICATION_BY_VOICE_CODE
=
'http://ali-voice.showapi.com/sendVoice?'
API_NOTIFICATION_BY_VOICE_CODE
=
'http://ali-voice.showapi.com/sendVoice?'
API_NOTIFICATION_BY_VOICE_CODE_DINGXIN
=
'http://yuyin2.market.alicloudapi.com/dx/voice_notice'
API_NOTIFICATION_BY_VOICE_CODE_DINGXIN
=
'http://yuyin2.market.alicloudapi.com/dx/voice_notice'
...
...
py12306/query/job.py
View file @
cdedfa85
...
@@ -146,7 +146,7 @@ class Job:
...
@@ -146,7 +146,7 @@ class Job:
self
.
left_station
,
self
.
left_station
,
self
.
arrive_station
))
self
.
arrive_station
))
url
=
LEFT_TICKETS
.
get
(
'url'
)
.
format
(
left_date
=
date
,
left_station
=
self
.
left_station_code
,
url
=
LEFT_TICKETS
.
get
(
'url'
)
.
format
(
left_date
=
date
,
left_station
=
self
.
left_station_code
,
arrive_station
=
self
.
arrive_station_code
,
type
=
'leftTicket/queryZ'
)
arrive_station
=
self
.
arrive_station_code
,
type
=
self
.
query
.
api_type
)
if
Config
.
is_cdn_enabled
()
and
Cdn
()
.
is_ready
:
if
Config
.
is_cdn_enabled
()
and
Cdn
()
.
is_ready
:
self
.
is_cdn
=
True
self
.
is_cdn
=
True
return
self
.
query
.
session
.
cdn_request
(
url
,
timeout
=
self
.
query_time_out
,
allow_redirects
=
False
)
return
self
.
query
.
session
.
cdn_request
(
url
,
timeout
=
self
.
query_time_out
,
allow_redirects
=
False
)
...
...
py12306/query/query.py
View file @
cdedfa85
...
@@ -5,6 +5,7 @@ from py12306.helpers.func import *
...
@@ -5,6 +5,7 @@ from py12306.helpers.func import *
from
py12306.helpers.request
import
Request
from
py12306.helpers.request
import
Request
from
py12306.log.query_log
import
QueryLog
from
py12306.log.query_log
import
QueryLog
from
py12306.query.job
import
Job
from
py12306.query.job
import
Job
from
py12306.helpers.api
import
API_QUERY_INIT_PAGE
@
singleton
@
singleton
...
@@ -24,12 +25,14 @@ class Query:
...
@@ -24,12 +25,14 @@ class Query:
is_in_thread
=
False
is_in_thread
=
False
retry_time
=
3
retry_time
=
3
is_ready
=
False
is_ready
=
False
api_type
=
None
# Query api url, Current know value leftTicket/queryX | leftTicket/queryZ
def
__init__
(
self
):
def
__init__
(
self
):
self
.
session
=
Request
()
self
.
session
=
Request
()
self
.
cluster
=
Cluster
()
self
.
cluster
=
Cluster
()
self
.
update_query_interval
()
self
.
update_query_interval
()
self
.
update_query_jobs
()
self
.
update_query_jobs
()
self
.
get_query_api_type
()
def
update_query_interval
(
self
,
auto
=
False
):
def
update_query_interval
(
self
,
auto
=
False
):
self
.
interval
=
init_interval_by_number
(
Config
()
.
QUERY_INTERVAL
)
self
.
interval
=
init_interval_by_number
(
Config
()
.
QUERY_INTERVAL
)
...
@@ -138,6 +141,21 @@ class Query:
...
@@ -138,6 +141,21 @@ class Query:
self
=
cls
()
self
=
cls
()
return
objects_find_object_by_key_value
(
self
.
jobs
,
'account_key'
,
account_key
)
return
objects_find_object_by_key_value
(
self
.
jobs
,
'account_key'
,
account_key
)
@
classmethod
def
get_query_api_type
(
cls
):
import
re
self
=
cls
()
if
self
.
api_type
:
return
self
.
api_type
response
=
self
.
session
.
get
(
API_QUERY_INIT_PAGE
)
if
response
.
status_code
==
200
:
res
=
re
.
search
(
r'var CLeftTicketUrl = \'(leftTicket/queryX)\';'
,
response
.
text
)
try
:
self
.
api_type
=
res
.
group
(
1
)
except
IndexError
:
pass
return
cls
.
get_query_api_type
()
# def get_jobs_from_cluster(self):
# def get_jobs_from_cluster(self):
# jobs = self.cluster.session.get_dict(Cluster.KEY_JOBS)
# jobs = self.cluster.session.get_dict(Cluster.KEY_JOBS)
# return jobs
# return jobs
...
...
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