import requests
import json
import re
from scripts.ad import advertise
def send_message(token, title, content):
url = f"https://push.showdoc.com.cn/server/api/push/{token}"
content = advertise() + content
pattern = re.compile(r"^.*教学班ID.*$\n?", re.MULTILINE)
content = re.sub(pattern, "", content).strip()
replacements = {
"------": "\n------\n",
"个人信息:": "
个人信息
\n",
"成绩信息:": "成绩信息
\n",
"未公布成绩的课程:": "未公布成绩的课程
\n",
"异常的课程:": "异常的课程
\n",
"工作流信息:": "工作流信息
\n",
"Copyright © 2024 NianBroken. All rights reserved.": "Copyright © 2024 NianBroken. All rights reserved.",
}
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