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
70e2c0e7
Commit
70e2c0e7
authored
Jan 13, 2019
by
Jalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增免费打码
parent
25049389
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
5 deletions
+48
-5
README.md
README.md
+6
-1
env.docker.py.example
env.docker.py.example
+2
-1
env.py.example
env.py.example
+4
-3
app.py
py12306/app.py
+2
-0
config.py
py12306/config.py
+1
-0
OCR.py
py12306/helpers/OCR.py
+30
-0
api.py
py12306/helpers/api.py
+3
-0
No files found.
README.md
View file @
70e2c0e7
...
...
@@ -17,6 +17,7 @@
-
[
x
]
动态修改配置文件
-
[
x
]
邮件通知
-
[
]
Web 管理页面
-
[
]
微信消息通知
## 使用
py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)
...
...
@@ -34,7 +35,9 @@ cp env.py.example env.py
```
自动打码
打码依赖于若快平台,需要先到
[
http://www.ruokuai.com
](
http://www.ruokuai.com/login
)
注册一个账号后填写到配置中
目前支持免费打码,和若快打码
注:免费打码无法保证持续可用,如失效请手动切换到若快平台,需要先到
[
http://www.ruokuai.com
](
http://www.ruokuai.com/login
)
注册一个账号后填写到配置中
语音通知
...
...
@@ -102,6 +105,8 @@ docker run -d -v $(pwd):/config -v py12306:/data pjialin/py12306
*
支持分布式集群
### 19-01-11
*
配置文件支持动态修改
### 19-01-12
*
新增免费打码
## 下单成功截图

...
...
env.docker.py.example
View file @
70e2c0e7
...
...
@@ -27,7 +27,8 @@ USER_HEARTBEAT_INTERVAL = 120
QUERY_JOB_THREAD_ENABLED = 0 # 是否开启多线程查询,开启后第个任务会单独分配线程处理
# 打码平台账号
# 目前只支持若快打码,注册地址:http://www.ruokuai.com/login
# 目前只支持免费打码接口 和 若快打码,注册地址:http://www.ruokuai.com/login
AUTO_CODE_PLATFORM = 'free' # 免费填写 free 若快 ruokuai # 免费打码无法保证持续可用,如失效请手动切换
AUTO_CODE_ACCOUNT = {
'user': 'your user name',
'pwd': 'your password'
...
...
env.py.example
View file @
70e2c0e7
...
...
@@ -27,8 +27,9 @@ USER_HEARTBEAT_INTERVAL = 120
QUERY_JOB_THREAD_ENABLED = 0 # 是否开启多线程查询,开启后第个任务会单独分配线程处理
# 打码平台账号
# 目前只支持若快打码,注册地址:http://www.ruokuai.com/login
AUTO_CODE_ACCOUNT = {
# 目前只支持免费打码接口 和 若快打码,注册地址:http://www.ruokuai.com/login
AUTO_CODE_PLATFORM = 'free' # 免费填写 free 若快 ruokuai # 免费打码无法保证持续可用,如失效请手动切换
AUTO_CODE_ACCOUNT = { # 使用 free 可用省略
'user': 'your user name',
'pwd': 'your password'
}
...
...
py12306/app.py
View file @
70e2c0e7
...
...
@@ -64,6 +64,7 @@ class App:
signal
.
signal
(
sign
,
self
.
handler_exit
)
pass
def
handler_exit
(
self
,
*
args
,
**
kwargs
):
"""
程序退出
...
...
@@ -79,6 +80,7 @@ class App:
@
classmethod
def
check_auto_code
(
cls
):
if
Config
()
.
AUTO_CODE_PLATFORM
==
'free'
:
return
True
if
not
Config
()
.
AUTO_CODE_ACCOUNT
.
get
(
'user'
)
or
not
Config
()
.
AUTO_CODE_ACCOUNT
.
get
(
'pwd'
):
return
False
return
True
...
...
py12306/config.py
View file @
70e2c0e7
...
...
@@ -20,6 +20,7 @@ class Config:
# 多线程查询
QUERY_JOB_THREAD_ENABLED
=
0
# 打码平台账号
AUTO_CODE_PLATFORM
=
''
AUTO_CODE_ACCOUNT
=
{
'user'
:
''
,
'pwd'
:
''
}
# 输出日志到文件
OUT_PUT_LOG_TO_FILE_ENABLED
=
0
...
...
py12306/helpers/OCR.py
View file @
70e2c0e7
...
...
@@ -2,6 +2,8 @@ import math
import
random
from
py12306.config
import
Config
from
py12306.helpers.api
import
*
from
py12306.helpers.request
import
Request
from
py12306.log.common_log
import
CommonLog
from
py12306.vender.ruokuai.main
import
RKClient
...
...
@@ -10,6 +12,10 @@ class OCR:
"""
图片识别
"""
session
=
None
def
__init__
(
self
):
self
.
session
=
Request
()
@
classmethod
def
get_img_position
(
cls
,
img
):
...
...
@@ -19,6 +25,8 @@ class OCR:
:return:
"""
self
=
cls
()
if
Config
()
.
AUTO_CODE_PLATFORM
==
'free'
:
return
self
.
get_image_by_free_site
(
img
)
return
self
.
get_img_position_by_ruokuai
(
img
)
def
get_img_position_by_ruokuai
(
self
,
img
):
...
...
@@ -46,6 +54,28 @@ class OCR:
positions
.
append
(
int
(
y
))
return
positions
def
get_image_by_free_site
(
self
,
img
):
data
=
{
'base64'
:
img
}
response
=
self
.
session
.
post
(
API_FREE_CODE_QCR_API
,
json
=
data
)
result
=
response
.
json
()
if
result
.
get
(
'success'
)
and
result
.
get
(
'check'
):
check_data
=
{
'check'
:
result
.
get
(
'check'
),
'img_buf'
:
img
,
'logon'
:
1
,
'type'
:
'D'
}
check_response
=
self
.
session
.
post
(
API_FREE_CODE_QCR_API_CHECK
,
json
=
check_data
)
check_result
=
check_response
.
json
()
if
check_result
.
get
(
'res'
):
position
=
check_result
.
get
(
'res'
)
return
position
.
replace
(
'('
,
''
)
.
replace
(
')'
,
''
)
.
split
(
','
)
CommonLog
.
print_auto_code_fail
(
result
.
get
(
"Error"
,
'-'
))
return
None
if
__name__
==
'__main__'
:
pass
...
...
py12306/helpers/api.py
View file @
70e2c0e7
...
...
@@ -44,3 +44,6 @@ API_QUERY_ORDER_WAIT_TIME = BASE_URL_OF_12306 + '/otn/confirmPassenger/queryOrde
API_NOTIFICATION_BY_VOICE_CODE
=
'http://ali-voice.showapi.com/sendVoice?'
API_FREE_CODE_QCR_API
=
'http://60.205.200.159/api'
API_FREE_CODE_QCR_API_CHECK
=
'http://check.huochepiao.360.cn/img_vcode'
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