因PushPlus推送服务在近期增加了:敏感词屏蔽、不实名就无法使用、实名需要收费等等严重影响用户体验的功能,所以本项目后续将使用Showdoc推送服务。

This commit is contained in:
NianBroken
2024-07-25 00:02:28 +08:00 Unverified
parent a03747b00d
commit 0a8b883b2e
28 changed files with 132 additions and 64 deletions
+27
View File
@@ -0,0 +1,27 @@
import requests
import json
import re
def send_message(token, title, content):
url = f"https://push.showdoc.com.cn/server/api/push/{token}"
pattern = re.compile(r"^.*教学班ID.*$\n?", re.MULTILINE)
content = re.sub(pattern, "", content).strip()
replacements = {
"------": "\n------\n",
"个人信息:": "<h1>个人信息</h1>\n",
"成绩信息:": "<h1>成绩信息</h1>\n",
"未公布成绩的课程:": "<h1>未公布成绩的课程</h1>\n",
"异常的课程:": "<h1>异常的课程</h1>\n",
"工作流信息:": "<h1>工作流信息</h1>\n",
}
for old, new in replacements.items():
content = content.replace(old, new)
data = {"title": title, "content": content}
body = json.dumps(data).encode(encoding="utf-8")
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=body, headers=headers)
# 解析 JSON 数据
response_dict = json.loads(response.text)
return response_dict