This repository was archived by the owner on Feb 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhook.py
More file actions
executable file
·85 lines (67 loc) · 2.24 KB
/
Webhook.py
File metadata and controls
executable file
·85 lines (67 loc) · 2.24 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
def Email(Cfg = None):
pass
def WeChat(Cfg = None):
pass
def DingTalk(Cfg = None):
import json
import time
import requests
if __name__ == '__main__':
from Merge import MergeCfg
else:
from .Merge import MergeCfg
Config = {
'Org': '',
'Data' : [],
'Token': ''
}
Config = MergeCfg(Config, Cfg)
Response = {
'ErrorCode': 0,
'ErrorMsg' : '',
}
CurrentTime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
MdText = '<font color=#6A65FF>**' + Config['Org'] + '**</font> \n\n ' + CurrentTime + ' \n\n'
for _ in Config['Data']:
# TITLE
if _.get('Title', '') == '':
MdText += ' --- \n\n '
else:
Color = _.get('Color', 'UNKNOW').upper()
if Color.startswith('#') and len(Color) == 7:
pass
else:
Color = {'PURPLE': '#6A65FF', 'RED': '#FF6666', 'GREEN': '#92D050', 'BLUE': '#76CCFF'}.get(Color, '#76CCFF')
MdText += ' --- \n\n <font color=' + Color + '>**' + _.get('Title', '') + '**</font> \n\n '
# TEXT
MdText += ' \n\n '.join(_.get('Text', [])) + ' \n\n '
MdText += '<font color=#6A65FF>' + Config['Org'] + '</font>'
Url = 'https://oapi.dingtalk.com/robot/send?access_token=' + Config['Token']
Hed = {
'Content-Type' : 'application/json'
}
Dat = {
'msgtype' : 'markdown',
'markdown': {
'title': Config['Org'],
'text' : MdText
}
}
for Attempt in range(3):
try:
Rsp = requests.post(Url, headers = Hed, params = None, data = json.dumps(Dat), cookies = None, proxies = None, timeout = 10)
Rst = Rsp.json()
if Rst['errcode'] != 0:
Response['ErrorCode'] = Rst['errcode']
Response['ErrorMsg'] = Rst['errmsg']
break
except Exception as errorMsg:
if Attempt == 2:
Response['ErrorCode'] = 50000
Response['ErrorMsg'] = f'Fail to send message, {str(errorMsg).lower().rstrip(".")}'
return Response
return Response
def Telegram(Cfg = None):
pass
def ServerChan(Cfg = None):
pass