-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathPush.py
53 lines (46 loc) · 1.47 KB
/
Push.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
import requests, json, logging, traceback
from os import environ, path
def get_environ(key, default="", output=True):
def no_read():
if output:
print(f"未填写环境变量 {key} 请添加")
exit(0)
return default
return environ.get(key) if environ.get(key) else no_read()
appToken = get_environ("WP_APP_TOKEN")
WP_TOPICIDS0 = get_environ("WP_TOPICIDS")
WP_TOPICIDS = [WP_TOPICIDS0]
uids = []
def PushMessageSetConfig(app_token,topicId, uid):
global appToken, uids,WP_TOPICIDS
appToken = app_token
WP_TOPICIDS = topicId
uids = uid
def PushMessage(summary, content):
if len(appToken) == 0:
return
url = "https://wxpusher.zjiecode.com/api/send/message"
payload = {
"appToken": appToken,
"content": content,
"summary": summary,
"contentType": 1,
"topicIds": WP_TOPICIDS,
"uids": uids
}
payload = json.dumps(payload)
logging.info("summary: %s, content: %s.", summary, content)
logging.info("appToken: %s, WP_TOPICIDS: %s.", appToken, WP_TOPICIDS)
header = {"content-type": "application/json"}
try:
r = requests.post(url, data = payload, headers = header)
logging.info(r.text)
except Exception as e:
logging.error("Exception: %s", traceback.format_exc())
pass
def main():
# logging.basicConfig(level=logging.INFO)
# PushMessage("test summary", "test content")
pass
if __name__ == "__main__":
main()