Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

添加qmsg推送 #21

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
# },
],
"together": True, # 是否合并发送结果, 不写或 True 时合并发送
"push": "workWechat", # 推送类型, together 为 True 或者不写时必须有, 否则不推送
"push": "qmsg", # 推送类型, together 为 True 或者不写时必须有, 否则不推送
}
1 change: 0 additions & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from config import config
from push import push


def main(*arg):
together = config.get("together")
type = config.get("push")
Expand Down
9 changes: 9 additions & 0 deletions push/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .workWeChat import workWechatRobot, workWechatApp
from .server import server
from .qmsg import qmsg
from .pushplus import pushplus

import os
Expand Down Expand Up @@ -62,6 +63,14 @@ def push(type: str, title: str, content):
)
except KeyError as key:
print(f"未配置企业微信的 {key}")
#qmsg推送
elif type == "qmsg":
try:
key = os.environ["qmsg"]
# 这里推送文本消息
res = qmsg(key).push_msg(dict2md.dict2md(content))
except KeyError:
print("未配置 qmsg 酱 的 key")
else:
print("未找到相关推送服务")
except Exception as ex:
Expand Down
23 changes: 23 additions & 0 deletions push/qmsg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests


class qmsg:
"""
qmsg(https://qmsg.zendee.cn/api)
"""

def __init__(self, key) -> None:
self.key = key
self.url = f"https://qmsg.zendee.cn:443/send/{self.key}"

def push_msg(self, msg) -> None:
"""
Parameters:
msg: 消息内容
"""
params = {"msg": msg}
res = requests.get(self.url, params=params).json()
if res["code"] == 0:
print("消息推送成功")
else:
print(f"推送错误, {res['info']}")