-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathnotification.py
73 lines (57 loc) · 1.93 KB
/
notification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import requests
import os
import time
#######################
# 通知服务
#######################
# [0,1,2] 0:不通知 1:server酱 2:bark服务
NOTIFYCFG = 0
SCKEY = '' # Server酱的SCKEY
BARK = '' # bark服务,自行搜索
##################################################################
def n0(a, b):
"""空函数,即不使用通知服务"""
print(">>>>未开启通知服务")
return
def serverJ(title, content):
"""server酱服务"""
sckey = SCKEY
if "SCKEY" in os.environ:
"""
判断是否运行自GitHub action,"SCKEY" 该参数与 repo里的Secrets的名称保持一致
"""
sckey = os.environ["SCKEY"]
if not sckey:
print("server酱服务的SCKEY未设置!!\n取消推送")
return
print("serverJ服务启动")
data = {
"text": title,
"desp": content
}
response = requests.post(f"https://sc.ftqq.com/{sckey}.send", data=data)
print(response.text)
def bark(title, content):
"""bark服务"""
bark_token = BARK
title = content.replace("#", "")
content = content.replace("#", "")
if "BARK" in os.environ:
"""
判断是否运行自GitHub action,"BARK" 该参数与 repo里的Secrets的名称保持一致
"""
bark_token = os.environ["BARK"]
if not bark_token:
print("bark服务的bark_token未设置!!\n取消推送")
return
response = requests.get(
f"""https://api.day.app/{bark_token}/{title}/{content}""")
print(response.text)
if "NOTIFYCFG" in os.environ:
NOTIFYCFG = eval(os.environ["NOTIFYCFG"])
notify = [n0, serverJ, bark][NOTIFYCFG]
if __name__ == "__main__":
print("通知服务测试")
start = time.time()
notify("QQRead脚本通知服务", "needYou2Know\n通知服务测试")
print("耗时: ", time.time()-start, "s")