-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdingLog.py
31 lines (25 loc) · 969 Bytes
/
dingLog.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
# 实现在钉钉使用机器人发送任务日志
from datetime import datetime
import requests
class DingLog:
def __init__(self, url: str):
now = datetime.now()
self.msg = now.strftime("%Y/%m/%d (%A) %H:%M:%S")
self.msg += "\n= = = = = = = = = = = = = = = = = ="
self.url = url
def end(self, msg: str, atAll=False):
headers = {"Content-Type": "application/json"}
self.msg += "\n= = = = = = = = = = = = = = = = = ="
self.info(msg)
if self.url is None or self.url == "ignore":
pass
elif self.url == "":
print(self.msg)
else:
data = {"msgtype": "text", "text": {"content": self.msg}}
if atAll:
data["at"] = {"isAtAll": "true"}
data = str(data).encode("utf-8")
requests.session().post(url=self.url, headers=headers, data=data)
def info(self, msg: str):
self.msg += "\n" + msg