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
996fc245
Commit
996fc245
authored
Feb 02, 2019
by
Zzde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加bark通知
parent
66ad9c9e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
0 deletions
+39
-0
env.py.example
env.py.example
+5
-0
app.py
py12306/app.py
+4
-0
config.py
py12306/config.py
+4
-0
notification.py
py12306/helpers/notification.py
+19
-0
common_log.py
py12306/log/common_log.py
+5
-0
order.py
py12306/order/order.py
+2
-0
No files found.
env.py.example
View file @
996fc245
...
@@ -71,6 +71,11 @@ SERVERCHAN_KEY = ''
...
@@ -71,6 +71,11 @@ SERVERCHAN_KEY = ''
PUSHBEAR_ENABLED = 0
PUSHBEAR_ENABLED = 0
PUSHBEAR_KEY = ''
PUSHBEAR_KEY = ''
# Bark 推送到ios设备
# 参考 https://www.v2ex.com/t/467407
BARK_ENABLED = 0
BARK_PUSH_URL = 'https://api.day.app/:your_token'
# 输出日志到文件
# 输出日志到文件
OUT_PUT_LOG_TO_FILE_ENABLED = 0
OUT_PUT_LOG_TO_FILE_ENABLED = 0
OUT_PUT_LOG_TO_FILE_PATH = 'runtime/12306.log' # 日志目录
OUT_PUT_LOG_TO_FILE_PATH = 'runtime/12306.log' # 日志目录
...
...
py12306/app.py
View file @
996fc245
...
@@ -130,6 +130,10 @@ class App:
...
@@ -130,6 +130,10 @@ class App:
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_TEST_SEND_PUSH_BEAR
)
.
flush
()
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_TEST_SEND_PUSH_BEAR
)
.
flush
()
Notification
.
push_bear
(
Config
()
.
PUSHBEAR_KEY
,
'测试发送消息'
,
'By py12306'
)
Notification
.
push_bear
(
Config
()
.
PUSHBEAR_KEY
,
'测试发送消息'
,
'By py12306'
)
if
Config
()
.
BARK_ENABLED
:
# Bark通知
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_TEST_SEND_PUSH_BARK
)
.
flush
()
Notification
.
push_bark
(
'测试发送信息'
)
@
classmethod
@
classmethod
def
run_check
(
cls
):
def
run_check
(
cls
):
"""
"""
...
...
py12306/config.py
View file @
996fc245
...
@@ -65,6 +65,10 @@ class Config:
...
@@ -65,6 +65,10 @@ class Config:
TELEGRAM_ENABLED
=
0
TELEGRAM_ENABLED
=
0
TELEGRAM_BOT_API_URL
=
''
TELEGRAM_BOT_API_URL
=
''
# Bark 推送配置
BARK_ENABLED
=
0
BARK_PUSH_URL
=
''
# ServerChan和PushBear配置
# ServerChan和PushBear配置
SERVERCHAN_ENABLED
=
0
SERVERCHAN_ENABLED
=
0
SERVERCHAN_KEY
=
'8474-ca071ADSFADSF'
SERVERCHAN_KEY
=
'8474-ca071ADSFADSF'
...
...
py12306/helpers/notification.py
View file @
996fc245
...
@@ -48,6 +48,11 @@ class Notification():
...
@@ -48,6 +48,11 @@ class Notification():
self
=
cls
()
self
=
cls
()
self
.
send_pushbear
(
skey
=
skey
,
title
=
title
,
content
=
content
)
self
.
send_pushbear
(
skey
=
skey
,
title
=
title
,
content
=
content
)
@
classmethod
def
push_bark
(
cls
,
content
=
''
):
self
=
cls
()
self
.
push_to_bark
(
content
)
def
send_voice_code_of_yiyuan
(
self
,
phone
,
name
=
''
,
content
=
''
):
def
send_voice_code_of_yiyuan
(
self
,
phone
,
name
=
''
,
content
=
''
):
"""
"""
发送语音验证码
发送语音验证码
...
@@ -152,6 +157,20 @@ class Notification():
...
@@ -152,6 +157,20 @@ class Notification():
response_error_message
=
result
.
get
(
'description'
)
response_error_message
=
result
.
get
(
'description'
)
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_SEND_TELEGRAM_FAIL
.
format
(
response_error_message
))
.
flush
()
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_SEND_TELEGRAM_FAIL
.
format
(
response_error_message
))
.
flush
()
def
push_to_bark
(
self
,
content
):
bark_url
=
Config
()
.
BARK_PUSH_URL
if
not
bark_url
:
return
False
response
=
self
.
session
.
request
(
url
=
bark_url
+
'/'
+
content
,
method
=
'get'
)
result
=
response
.
json
()
response_status
=
result
.
get
(
'code'
)
if
response_status
==
200
:
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_SEND_BARK_SUCCESS
)
.
flush
()
else
:
response_error_message
=
result
.
get
(
'message'
)
CommonLog
.
add_quick_log
(
CommonLog
.
MESSAGE_SEND_BARK_FAIL
.
format
(
response_error_message
))
.
flush
()
def
send_serverchan
(
self
,
skey
,
title
,
content
):
def
send_serverchan
(
self
,
skey
,
title
,
content
):
from
lightpush
import
lightpush
from
lightpush
import
lightpush
lgp
=
lightpush
()
lgp
=
lightpush
()
...
...
py12306/log/common_log.py
View file @
996fc245
...
@@ -27,6 +27,7 @@ class CommonLog(BaseLog):
...
@@ -27,6 +27,7 @@ class CommonLog(BaseLog):
MESSAGE_TEST_SEND_TELEGRAM
=
'正在测试推送到Telegram...'
MESSAGE_TEST_SEND_TELEGRAM
=
'正在测试推送到Telegram...'
MESSAGE_TEST_SEND_SERVER_CHAN
=
'正在测试发送ServerChan消息...'
MESSAGE_TEST_SEND_SERVER_CHAN
=
'正在测试发送ServerChan消息...'
MESSAGE_TEST_SEND_PUSH_BEAR
=
'正在测试发送PushBear消息...'
MESSAGE_TEST_SEND_PUSH_BEAR
=
'正在测试发送PushBear消息...'
MESSAGE_TEST_SEND_PUSH_BARK
=
'正在测试发送Bark消息...'
MESSAGE_CONFIG_FILE_DID_CHANGED
=
'配置文件已修改,正在重新加载中
\n
'
MESSAGE_CONFIG_FILE_DID_CHANGED
=
'配置文件已修改,正在重新加载中
\n
'
MESSAGE_API_RESPONSE_CAN_NOT_BE_HANDLE
=
'接口返回错误'
MESSAGE_API_RESPONSE_CAN_NOT_BE_HANDLE
=
'接口返回错误'
...
@@ -43,6 +44,9 @@ class CommonLog(BaseLog):
...
@@ -43,6 +44,9 @@ class CommonLog(BaseLog):
MESSAGE_SEND_PUSH_BEAR_SUCCESS
=
'发送成功,请检查微信'
MESSAGE_SEND_PUSH_BEAR_SUCCESS
=
'发送成功,请检查微信'
MESSAGE_SEND_PUSH_BEAR_FAIL
=
'PushBear发送失败,请检查KEY'
MESSAGE_SEND_PUSH_BEAR_FAIL
=
'PushBear发送失败,请检查KEY'
MESSAGE_SEND_BARK_SUCCESS
=
'Bark推送成功'
MESSAGE_SEND_BARK_FAIL
=
'Bark推送失败,错误原因 {}'
MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE
=
'请先打开配置项中的:OUT_PUT_LOG_TO_FILE_ENABLED ( 输出到文件 )'
MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE
=
'请先打开配置项中的:OUT_PUT_LOG_TO_FILE_ENABLED ( 输出到文件 )'
MESSAGE_GET_RESPONSE_FROM_FREE_AUTO_CODE
=
'从免费打码获取结果失败'
MESSAGE_GET_RESPONSE_FROM_FREE_AUTO_CODE
=
'从免费打码获取结果失败'
...
@@ -96,6 +100,7 @@ class CommonLog(BaseLog):
...
@@ -96,6 +100,7 @@ class CommonLog(BaseLog):
self
.
add_quick_log
(
'钉钉通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
DINGTALK_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'钉钉通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
DINGTALK_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'Telegram通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
TELEGRAM_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'Telegram通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
TELEGRAM_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'ServerChan通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
SERVERCHAN_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'ServerChan通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
SERVERCHAN_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
'Bark通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
BARK_ENABLED
,
enable
,
disable
)))
self
.
add_quick_log
(
self
.
add_quick_log
(
'PushBear通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
PUSHBEAR_ENABLED
,
enable
,
disable
)))
.
flush
(
sep
=
'
\t\t
'
)
'PushBear通知: {}'
.
format
(
get_true_false_text
(
Config
()
.
PUSHBEAR_ENABLED
,
enable
,
disable
)))
.
flush
(
sep
=
'
\t\t
'
)
self
.
add_quick_log
(
'查询间隔: {} 秒'
.
format
(
Config
()
.
QUERY_INTERVAL
))
self
.
add_quick_log
(
'查询间隔: {} 秒'
.
format
(
Config
()
.
QUERY_INTERVAL
))
...
...
py12306/order/order.py
View file @
996fc245
...
@@ -99,6 +99,8 @@ class Order:
...
@@ -99,6 +99,8 @@ class Order:
if
Config
()
.
PUSHBEAR_ENABLED
:
# PushBear通知
if
Config
()
.
PUSHBEAR_ENABLED
:
# PushBear通知
Notification
.
push_bear
(
Config
()
.
PUSHBEAR_KEY
,
OrderLog
.
MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE
,
Notification
.
push_bear
(
Config
()
.
PUSHBEAR_KEY
,
OrderLog
.
MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE
,
normal_message
+
info_message
)
normal_message
+
info_message
)
if
Config
()
.
BARK_ENABLED
:
Notification
.
push_bark
(
normal_message
+
info_message
)
if
Config
()
.
NOTIFICATION_BY_VOICE_CODE
:
# 语音通知
if
Config
()
.
NOTIFICATION_BY_VOICE_CODE
:
# 语音通知
if
Config
()
.
NOTIFICATION_VOICE_CODE_TYPE
==
'dingxin'
:
if
Config
()
.
NOTIFICATION_VOICE_CODE_TYPE
==
'dingxin'
:
...
...
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