forked from MurphyZzzzz/Hello_to_BUPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverJiang.py
67 lines (53 loc) · 2.14 KB
/
serverJiang.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
import time
import requests,datetime
from constant import *
class ServerJiangNotifier(INotifier):
PLATFORM_NAME = 'Server 酱'
def __init__(self, *, sckey: str, sess: requests.Session):
self._sckey = sckey
self._sess = sess
def notify(self, *, success, msg, data, username, name) -> None:
"""发送消息。"""
title_suc,title_eor,bodys=[],[],[]
title_suc_str,title_eor_str,body_str='','',''
for i in range(len(USERS)):
if success[i]:
title_suc += [f'{name[i]}']
if msg[i] is not None:
body = f'\n学号{username[i]},{name[i]} 填报成功, 服务器的返回是:\n{msg[i]}\n 填报数据:\n{data[i]}\n'
else:
body = '成功'
else:
title_eor += [f'{name[i]}']
if msg[i] is not None:
body = f'学号{username[i]} 填报失败:产生如下异常:\n{msg[i]}\n 填报数据:\n{data[i]}\n'
else:
body = '失败'
bodys+=[body]
for i in range(len(title_suc)):
title_suc_str+=title_suc[i]
if i!= len(title_suc)-1:
title_suc_str+='、'
else:
title_suc_str+="填报成功!"
if len(title_eor)==0:
title_suc_str="所有填报成功"
for i in range(len(title_eor)):
title_eor_str+=title_eor[i]
if i!= len(title_eor)-1:
title_eor_str+='、'
else:
title_eor_str+="填报失败!"
for i in range(len(bodys)):
body_str+=bodys[i]
# Server 不允许短时间重复发送相同内容,故加上时间
time_str = str(int(time.time()))[-3:]
# 调用 Server 酱接口发送消息
sc_res_raw = self._sess.post(
f'https://sctapi.ftqq.com/{self._sckey}.send',
data={
'title': f'{datetime.date.today()}:{title_suc_str}{title_eor_str}',
'desp': f'{body_str}\n{time_str}',
},
timeout=TIMEOUT_SECOND,
)