MCPcopy Create free account
hub / github.com/Tyaoo/picker / wecomBot

Class wecomBot

bot.py:64–98  ·  view source on GitHub ↗

企业微信群机器人 https://developer.work.weixin.qq.com/document/path/91770

Source from the content-addressed store, hash-verified

62
63
64class wecomBot:
65 """企业微信群机器人
66 https://developer.work.weixin.qq.com/document/path/91770
67 """
68 def __init__(self, key, proxy_url='') -> None:
69 self.key = key
70 self.proxy = {'http': proxy_url, 'https': proxy_url} if proxy_url else {'http': None, 'https': None}
71
72 @staticmethod
73 def parse_results(results: list):
74 text_list = []
75 for result in results:
76 (feed, value), = result.items()
77 text = f'## {feed}\n'
78 for title, link in value.items():
79 text += f'- [{title}]({link})\n'
80 text_list.append(text.strip())
81 return text_list
82
83 def send(self, text_list: list):
84 limiter = Limiter(Rate(20, Duration.MINUTE)) # 频率限制,20条/分钟
85 for text in text_list:
86 with limiter.ratelimit('identity', delay=True):
87 print(f'{len(text)} {text[:50]}...{text[-50:]}')
88
89 data = {"msgtype": "markdown", "markdown": {"content": text}}
90 headers = {'Content-Type': 'application/json'}
91 url = f'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={self.key}'
92 r = requests.post(url=url, headers=headers, data=json.dumps(data), proxies=self.proxy)
93
94 if r.status_code == 200:
95 Color.print_success('[+] wecomBot 发送成功')
96 else:
97 Color.print_failed('[-] wecomBot 发送失败')
98 print(r.text)
99
100
101class dingtalkBot:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected