add ServerChan and PushBear支持
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
- [x] 动态修改配置文件
|
- [x] 动态修改配置文件
|
||||||
- [x] 邮件通知
|
- [x] 邮件通知
|
||||||
- [x] Web 管理页面
|
- [x] Web 管理页面
|
||||||
- [ ] 微信消息通知
|
- [x] 微信消息通知
|
||||||
|
|
||||||
## 使用
|
## 使用
|
||||||
py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)
|
py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试)
|
||||||
@@ -125,6 +125,10 @@ docker run -d -v $(pwd):/config -v py12306:/data pjialin/py12306
|
|||||||
|
|
||||||
新增 Web 页面支持
|
新增 Web 页面支持
|
||||||
|
|
||||||
|
- 19-01-15
|
||||||
|
|
||||||
|
新增ServerChan和PushBear支持
|
||||||
|
|
||||||
|
|
||||||
## 截图
|
## 截图
|
||||||
### Web 管理页面
|
### Web 管理页面
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ DINGTALK_WEBHOOK = 'https://oapi.dingtalk.com/robot/send?access_token=your token
|
|||||||
TELEGRAM_ENABLED = 0
|
TELEGRAM_ENABLED = 0
|
||||||
TELEGRAM_BOT_API_URL = 'https://tgbot.lbyczf.com/sendMessage/:your_token'
|
TELEGRAM_BOT_API_URL = 'https://tgbot.lbyczf.com/sendMessage/:your_token'
|
||||||
|
|
||||||
|
# ServerChan和PushBear配置
|
||||||
|
SERVERCHAN_ENABLED = 0
|
||||||
|
PUSHBEAR_ENABLED = 0
|
||||||
|
SKEY = 'SCUdafadsfasfdafdf45234234234'
|
||||||
|
|
||||||
# 输出日志到文件 (Docker 中不建议修改此组配置项)
|
# 输出日志到文件 (Docker 中不建议修改此组配置项)
|
||||||
OUT_PUT_LOG_TO_FILE_ENABLED = 1
|
OUT_PUT_LOG_TO_FILE_ENABLED = 1
|
||||||
OUT_PUT_LOG_TO_FILE_PATH = '/config/12306.log' # 日志目录
|
OUT_PUT_LOG_TO_FILE_PATH = '/config/12306.log' # 日志目录
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ DINGTALK_WEBHOOK = 'https://oapi.dingtalk.com/robot/send?access_token=your token
|
|||||||
TELEGRAM_ENABLED = 0
|
TELEGRAM_ENABLED = 0
|
||||||
TELEGRAM_BOT_API_URL = 'https://tgbot.lbyczf.com/sendMessage/:your_token'
|
TELEGRAM_BOT_API_URL = 'https://tgbot.lbyczf.com/sendMessage/:your_token'
|
||||||
|
|
||||||
|
# ServerChan和PushBear配置
|
||||||
|
SERVERCHAN_ENABLED = 0
|
||||||
|
PUSHBEAR_ENABLED = 0
|
||||||
|
SKEY = 'SCUdafadsfasfdafdf45234234234'
|
||||||
|
|
||||||
# 输出日志到文件
|
# 输出日志到文件
|
||||||
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' # 日志目录
|
||||||
|
|||||||
1
main.py
1
main.py
@@ -38,6 +38,7 @@ def test():
|
|||||||
座位验证
|
座位验证
|
||||||
乘客验证
|
乘客验证
|
||||||
语音验证码验证
|
语音验证码验证
|
||||||
|
通知验证
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
Const.IS_TEST = True
|
Const.IS_TEST = True
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class App:
|
|||||||
Notification.voice_code(Config().NOTIFICATION_VOICE_CODE_PHONE, '张三',
|
Notification.voice_code(Config().NOTIFICATION_VOICE_CODE_PHONE, '张三',
|
||||||
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_VOICE_CODE_CONTENT.format('北京',
|
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_VOICE_CODE_CONTENT.format('北京',
|
||||||
'深圳'))
|
'深圳'))
|
||||||
if Config().EMAIL_ENABLED: # 语音通知
|
if Config().EMAIL_ENABLED: # 邮件通知
|
||||||
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_EMAIL).flush()
|
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_EMAIL).flush()
|
||||||
Notification.send_email(Config().EMAIL_RECEIVER, '测试发送邮件', 'By py12306')
|
Notification.send_email(Config().EMAIL_RECEIVER, '测试发送邮件', 'By py12306')
|
||||||
|
|
||||||
@@ -117,6 +117,14 @@ class App:
|
|||||||
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_TELEGRAM).flush()
|
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_TELEGRAM).flush()
|
||||||
Notification.send_to_telegram('测试发送信息')
|
Notification.send_to_telegram('测试发送信息')
|
||||||
|
|
||||||
|
if Config().SERVERCHAN_ENABLED: # ServerChan通知
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_SERVER_CHAN).flush()
|
||||||
|
Notification.server_chan(Config().SKEY, '测试发送消息', 'By py12306')
|
||||||
|
|
||||||
|
if Config().PUSHBEAR_ENABLED: # PushBear通知
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_TEST_SEND_PUSH_BEAR).flush()
|
||||||
|
Notification.push_bear(Config().SKEY, '测试发送消息', 'By py12306')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_check(cls):
|
def run_check(cls):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ class Config:
|
|||||||
TELEGRAM_ENABLED = 0
|
TELEGRAM_ENABLED = 0
|
||||||
TELEGRAM_BOT_API_URL = ''
|
TELEGRAM_BOT_API_URL = ''
|
||||||
|
|
||||||
|
# ServerChan和PushBear配置
|
||||||
|
SERVERCHAN_ENABLED = 0
|
||||||
|
PUSHBEAR_ENABLED = 0
|
||||||
|
SKEY = ''
|
||||||
|
|
||||||
# 邮箱配置
|
# 邮箱配置
|
||||||
EMAIL_ENABLED = 0
|
EMAIL_ENABLED = 0
|
||||||
EMAIL_SENDER = ''
|
EMAIL_SENDER = ''
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from py12306.helpers.api import *
|
|||||||
from py12306.helpers.request import Request
|
from py12306.helpers.request import Request
|
||||||
from py12306.log.common_log import CommonLog
|
from py12306.log.common_log import CommonLog
|
||||||
|
|
||||||
|
|
||||||
class Notification():
|
class Notification():
|
||||||
"""
|
"""
|
||||||
通知类
|
通知类
|
||||||
@@ -35,6 +34,16 @@ class Notification():
|
|||||||
self = cls()
|
self = cls()
|
||||||
self.send_to_telegram_bot(content=content)
|
self.send_to_telegram_bot(content=content)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def server_chan(cls, skey='', title='', content=''):
|
||||||
|
self = cls()
|
||||||
|
self.send_serverchan(skey=skey, title=title, content=content)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def push_bear(cls, skey='', title='', content=''):
|
||||||
|
self = cls()
|
||||||
|
self.send_pushbear(skey=skey, title=title, content=content)
|
||||||
|
|
||||||
def send_voice_code_of_yiyuan(self, phone, name='', content=''):
|
def send_voice_code_of_yiyuan(self, phone, name='', content=''):
|
||||||
"""
|
"""
|
||||||
发送语音验证码
|
发送语音验证码
|
||||||
@@ -110,6 +119,26 @@ 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 send_serverchan(self, skey, title, content):
|
||||||
|
from lightpush import lightpush
|
||||||
|
lgp = lightpush()
|
||||||
|
lgp.set_single_push(key=skey)
|
||||||
|
try:
|
||||||
|
lgp.single_push(title, content)
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_SERVER_CHAN_SUCCESS).flush()
|
||||||
|
except Exception as e:
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_SERVER_CHAN_FAIL.format(e)).flush()
|
||||||
|
|
||||||
|
def send_pushbear(self, skey, title, content):
|
||||||
|
from lightpush import lightpush
|
||||||
|
lgp = lightpush()
|
||||||
|
lgp.set_group_push(key=skey)
|
||||||
|
try:
|
||||||
|
lgp.group_push(title, content)
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_PUSH_BEAR_SUCCESS).flush()
|
||||||
|
except Exception as e:
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_PUSH_BEAR_SUCCESS.format(e)).flush()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
name = '张三4'
|
name = '张三4'
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ class CommonLog(BaseLog):
|
|||||||
MESSAGE_TEST_SEND_EMAIL = '正在测试发送邮件...'
|
MESSAGE_TEST_SEND_EMAIL = '正在测试发送邮件...'
|
||||||
MESSAGE_TEST_SEND_DINGTALK = '正在测试发送钉钉消息...'
|
MESSAGE_TEST_SEND_DINGTALK = '正在测试发送钉钉消息...'
|
||||||
MESSAGE_TEST_SEND_TELEGRAM = '正在测试推送到Telegram...'
|
MESSAGE_TEST_SEND_TELEGRAM = '正在测试推送到Telegram...'
|
||||||
|
MESSAGE_TEST_SEND_SERVER_CHAN = '正在测试发送ServerChan消息...'
|
||||||
|
MESSAGE_TEST_SEND_PUSH_BEAR = '正在测试发送PushBear消息...'
|
||||||
|
|
||||||
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 = '接口返回错误'
|
||||||
@@ -35,6 +37,12 @@ class CommonLog(BaseLog):
|
|||||||
MESSAGE_SEND_TELEGRAM_SUCCESS = 'Telegram推送成功'
|
MESSAGE_SEND_TELEGRAM_SUCCESS = 'Telegram推送成功'
|
||||||
MESSAGE_SEND_TELEGRAM_FAIL = 'Telegram推送失败,错误原因 {}'
|
MESSAGE_SEND_TELEGRAM_FAIL = 'Telegram推送失败,错误原因 {}'
|
||||||
|
|
||||||
|
MESSAGE_SEND_SERVER_CHAN_SUCCESS = '发送成功,请检查微信'
|
||||||
|
MESSAGE_SEND_SERVER_CHAN_FAIL = 'ServerChan发送失败,请检查KEY'
|
||||||
|
|
||||||
|
MESSAGE_SEND_PUSH_BEAR_SUCCESS = '发送成功,请检查微信'
|
||||||
|
MESSAGE_SEND_PUSH_BEAR_FAIL = 'PushBear发送失败,请检查KEY'
|
||||||
|
|
||||||
MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE = '请先打开配置:输出到文件'
|
MESSAGE_OUTPUT_TO_FILE_IS_UN_ENABLE = '请先打开配置:输出到文件'
|
||||||
|
|
||||||
MESSAGE_GET_RESPONSE_FROM_FREE_AUTO_CODE = '从免费打码获取结果失败'
|
MESSAGE_GET_RESPONSE_FROM_FREE_AUTO_CODE = '从免费打码获取结果失败'
|
||||||
@@ -77,6 +85,8 @@ class CommonLog(BaseLog):
|
|||||||
self.add_quick_log('邮件通知: {}'.format(get_true_false_text(Config().EMAIL_ENABLED, enable, disable)))
|
self.add_quick_log('邮件通知: {}'.format(get_true_false_text(Config().EMAIL_ENABLED, enable, disable)))
|
||||||
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('PushBear通知: {}'.format(get_true_false_text(Config().PUSHBEAR_ENABLED, enable, disable)))
|
||||||
self.add_quick_log('查询间隔: {} 秒'.format(Config().QUERY_INTERVAL))
|
self.add_quick_log('查询间隔: {} 秒'.format(Config().QUERY_INTERVAL))
|
||||||
self.add_quick_log('用户心跳检测间隔: {} 秒'.format(Config().USER_HEARTBEAT_INTERVAL))
|
self.add_quick_log('用户心跳检测间隔: {} 秒'.format(Config().USER_HEARTBEAT_INTERVAL))
|
||||||
self.add_quick_log('WEB 管理页面: {}'.format(get_true_false_text(Config().WEB_ENABLE, enable, disable)))
|
self.add_quick_log('WEB 管理页面: {}'.format(get_true_false_text(Config().WEB_ENABLE, enable, disable)))
|
||||||
|
|||||||
@@ -87,6 +87,12 @@ class Order:
|
|||||||
if Config().TELEGRAM_ENABLED: # Telegram推送
|
if Config().TELEGRAM_ENABLED: # Telegram推送
|
||||||
Notification.send_to_telegram(
|
Notification.send_to_telegram(
|
||||||
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_EMAIL_CONTENT.format(self.order_id))
|
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_EMAIL_CONTENT.format(self.order_id))
|
||||||
|
if Config().SERVERCHAN_ENABLED: # ServerChan通知
|
||||||
|
Notification.server_chan(Config().SKEY, OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE,
|
||||||
|
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_EMAIL_CONTENT.format(self.order_id))
|
||||||
|
if Config().PUSHBEAR_ENABLED: # PushBear通知
|
||||||
|
Notification.push_bear(Config().SKEY, OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_TITLE,
|
||||||
|
OrderLog.MESSAGE_ORDER_SUCCESS_NOTIFICATION_OF_EMAIL_CONTENT.format(self.order_id))
|
||||||
while sustain_time: # TODO 后面直接查询有没有待支付的订单就可以
|
while sustain_time: # TODO 后面直接查询有没有待支付的订单就可以
|
||||||
num += 1
|
num += 1
|
||||||
if Config().NOTIFICATION_BY_VOICE_CODE: # 语音通知
|
if Config().NOTIFICATION_BY_VOICE_CODE: # 语音通知
|
||||||
|
|||||||
@@ -28,4 +28,5 @@ urllib3==1.24.1
|
|||||||
w3lib==1.19.0
|
w3lib==1.19.0
|
||||||
websockets==7.0
|
websockets==7.0
|
||||||
Werkzeug==0.14.1
|
Werkzeug==0.14.1
|
||||||
DingtalkChatbot==1.3.0
|
DingtalkChatbot==1.3.0
|
||||||
|
lightpush==0.1.3
|
||||||
Reference in New Issue
Block a user