feat: 添加工作时间飞书新消息通知功能

This commit is contained in:
2021-08-07 17:23:12 +08:00
parent 55d90b40bd
commit d6142b6c8c
2 changed files with 36 additions and 5 deletions
+6 -5
View File
@@ -84,8 +84,9 @@ if __name__ == "__main__":
wxbot_instance['current'] = wxbot wxbot_instance['current'] = wxbot
wxbot.DEBUG = args.debug wxbot.DEBUG = args.debug
wxbot.saveFolder = args.data_dir wxbot.saveFolder = args.data_dir
WXBotThreadStarter(wxbot).start() wxbot.start()
if args.serve: # WXBotThreadStarter(wxbot).start()
start_server = websockets.serve(message_consumer, "localhost", 8083) # if args.serve:
asyncio.get_event_loop().run_until_complete(start_server) # start_server = websockets.serve(message_consumer, "localhost", 8083)
asyncio.get_event_loop().run_forever() # asyncio.get_event_loop().run_until_complete(start_server)
# asyncio.get_event_loop().run_forever()
+30
View File
@@ -5,6 +5,8 @@ import queue
import logging import logging
import os import os
import requests
class Subscription: class Subscription:
def __init__(self, queue): def __init__(self, queue):
@@ -234,6 +236,34 @@ class WXBot(WebWeixin):
params["content"] = "[未识别消息]" + msg["Content"] params["content"] = "[未识别消息]" + msg["Content"]
self.db_conn.execute(sql, params) self.db_conn.execute(sql, params)
self.db_conn.commit() self.db_conn.commit()
# 工作时间发送新消息提醒到飞书
curr_time_struct = time.localtime(time.time())
if curr_time_struct.tm_hour >= 10 and curr_time_struct.tm_hour < 19:
requests.post(
"https://open.feishu.cn/open-apis/bot/v2/hook/30bda541-46de-40b7-8881-31b77deadc35",
headers={"Content-Type": "application/json"},
json={
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "" + params["from_name"] + "】发来一条新消息",
"content": [
[
{
"tag": "text",
"text": "【微信】收到一条来自【"
+ params["from_name"]
+ "】的消息",
}
]
],
}
}
},
},
)
for subscription in self.subscriptions: for subscription in self.subscriptions:
if ( if (
not subscription.queue.empty() not subscription.queue.empty()