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
afe2962b
Commit
afe2962b
authored
Jan 07, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复打码错误
parent
ac5cc082
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
7 deletions
+14
-7
main.py
main.py
+1
-1
OCR.py
py12306/helpers/OCR.py
+0
-1
auth_code.py
py12306/helpers/auth_code.py
+10
-3
base.py
py12306/log/base.py
+2
-2
common_log.py
py12306/log/common_log.py
+1
-0
No files found.
main.py
View file @
afe2962b
...
@@ -10,7 +10,7 @@ from py12306.user.user import User
...
@@ -10,7 +10,7 @@ from py12306.user.user import User
def
main
():
def
main
():
# Thread(target=Query.run).start() # 余票查询
# Thread(target=Query.run).start() # 余票查询
create_thread_and_run
(
User
,
'run'
,
wait
=
False
)
create_thread_and_run
(
User
,
'run'
,
wait
=
False
)
Query
.
run
()
#
Query.run()
# Query.run()
# Query.run()
pass
pass
...
...
py12306/helpers/OCR.py
View file @
afe2962b
...
@@ -17,7 +17,6 @@ class OCR:
...
@@ -17,7 +17,6 @@ class OCR:
"""
"""
self
=
cls
()
self
=
cls
()
return
self
.
get_img_position_by_ruokuai
(
img_path
)
return
self
.
get_img_position_by_ruokuai
(
img_path
)
pass
def
get_img_position_by_ruokuai
(
self
,
img_path
):
def
get_img_position_by_ruokuai
(
self
,
img_path
):
ruokuai_account
=
config
.
AUTO_CODE_ACCOUNT
ruokuai_account
=
config
.
AUTO_CODE_ACCOUNT
...
...
py12306/helpers/auth_code.py
View file @
afe2962b
...
@@ -17,7 +17,7 @@ class AuthCode:
...
@@ -17,7 +17,7 @@ class AuthCode:
"""
"""
session
=
None
session
=
None
data_path
=
config
.
RUNTIME_DIR
data_path
=
config
.
RUNTIME_DIR
retry_time
=
1
retry_time
=
5
def
__init__
(
self
,
session
):
def
__init__
(
self
,
session
):
self
.
session
=
session
self
.
session
=
session
...
@@ -27,12 +27,19 @@ class AuthCode:
...
@@ -27,12 +27,19 @@ class AuthCode:
self
=
cls
(
session
)
self
=
cls
(
session
)
img_path
=
self
.
download_code
()
img_path
=
self
.
download_code
()
position
=
OCR
.
get_img_position
(
img_path
)
position
=
OCR
.
get_img_position
(
img_path
)
if
not
position
:
# 打码失败
return
self
.
retry_get_auth_code
()
answer
=
','
.
join
(
map
(
str
,
position
))
answer
=
','
.
join
(
map
(
str
,
position
))
if
not
self
.
check_code
(
answer
):
if
not
self
.
check_code
(
answer
):
time
.
sleep
(
self
.
retry_time
)
return
self
.
retry_get_auth_code
()
return
self
.
get_auth_code
(
session
)
return
position
return
position
def
retry_get_auth_code
(
self
):
# TODO 安全次数检测
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_RETRY_AUTH_CODE
.
format
(
self
.
retry_time
))
time
.
sleep
(
self
.
retry_time
)
return
self
.
get_auth_code
(
self
.
session
)
def
download_code
(
self
):
def
download_code
(
self
):
url
=
API_AUTH_CODE_DOWNLOAD
.
get
(
'url'
)
.
format
(
random
=
random
.
random
())
url
=
API_AUTH_CODE_DOWNLOAD
.
get
(
'url'
)
.
format
(
random
=
random
.
random
())
code_path
=
self
.
data_path
+
'code.png'
code_path
=
self
.
data_path
+
'code.png'
...
...
py12306/log/base.py
View file @
afe2962b
...
@@ -30,7 +30,7 @@ class BaseLog:
...
@@ -30,7 +30,7 @@ class BaseLog:
if
is_main_thread
():
if
is_main_thread
():
logs
=
self
.
logs
logs
=
self
.
logs
else
:
else
:
logs
=
self
.
thread_logs
[
current_thread_id
()]
logs
=
self
.
thread_logs
.
get
(
current_thread_id
())
# for i in logs:
# for i in logs:
print
(
*
logs
,
sep
=
sep
,
end
=
end
,
file
=
file
)
print
(
*
logs
,
sep
=
sep
,
end
=
end
,
file
=
file
)
if
self
.
quick_log
:
if
self
.
quick_log
:
...
@@ -39,7 +39,7 @@ class BaseLog:
...
@@ -39,7 +39,7 @@ class BaseLog:
if
is_main_thread
():
if
is_main_thread
():
self
.
logs
=
[]
self
.
logs
=
[]
else
:
else
:
del
self
.
thread_logs
[
current_thread_id
()]
if
logs
:
del
self
.
thread_logs
[
current_thread_id
()]
# print(self.logs)
# print(self.logs)
@
classmethod
@
classmethod
...
...
py12306/log/common_log.py
View file @
afe2962b
...
@@ -5,6 +5,7 @@ from py12306.helpers.func import *
...
@@ -5,6 +5,7 @@ from py12306.helpers.func import *
@
singleton
@
singleton
class
CommonLog
(
BaseLog
):
class
CommonLog
(
BaseLog
):
MESSAGE_12306_IS_CLOSED
=
'当前时间: {} | 12306 休息时间,程序将在明天早上 6 点自动运行'
MESSAGE_12306_IS_CLOSED
=
'当前时间: {} | 12306 休息时间,程序将在明天早上 6 点自动运行'
MESSAGE_RETRY_AUTH_CODE
=
'{} 秒后重新获取验证码'
def
__init__
(
self
):
def
__init__
(
self
):
super
()
.
__init__
()
super
()
.
__init__
()
...
...
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