|
@@ -0,0 +1,92 @@
|
|
|
+"""
|
|
|
+独立执行,每个人执行一次,单日总量到达 300 即执行一次
|
|
|
+"""
|
|
|
+import json
|
|
|
+import datetime
|
|
|
+import time
|
|
|
+
|
|
|
+import schedule
|
|
|
+import requests
|
|
|
+
|
|
|
+from common.db import RedisClient
|
|
|
+
|
|
|
+
|
|
|
+def bot(name):
|
|
|
+ """
|
|
|
+ 报警机器人
|
|
|
+ """
|
|
|
+ id_dict = {
|
|
|
+ "余海涛": "ou_b87d153e200a04de3d82b1b9276e8f90",
|
|
|
+ "范军": "ou_fce9cfef186e260e70554b47fee70a34",
|
|
|
+ "罗情": "ou_88139cd84c2d105c2e1d699c14ec3375",
|
|
|
+ "鲁涛": "ou_7986cccb78e6c981db8d0eef93443d05",
|
|
|
+ "王雪珂": "ou_2233fb8e1302314bae166fcfa144151f",
|
|
|
+ "邓锋": "ou_379d37645f929e1e6553a75aecda42a2"
|
|
|
+ }
|
|
|
+ url = "https://open.feishu.cn/open-apis/bot/v2/hook/df47bb77-ecaa-4628-b076-aae776415ae8"
|
|
|
+ headers = {"Content-Type": "application/json"}
|
|
|
+ payload = {
|
|
|
+ "msg_type": "interactive",
|
|
|
+ "card": {
|
|
|
+ "elements": [
|
|
|
+ {
|
|
|
+ "tag": "div",
|
|
|
+ "text": {
|
|
|
+ "content": "抓取数量触发限量通知, <at id={}></at>, <at id={}></at>, <at id={}></at>\n".format(
|
|
|
+ id_dict[name], id_dict["邓锋"], id_dict["王雪珂"]
|
|
|
+ ),
|
|
|
+ "tag": "lark_md",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "tag": "div",
|
|
|
+ "text": {
|
|
|
+ "content": "当天已经入库 300 条视频",
|
|
|
+ "tag": "lark_md",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ "header": {"title": {"content": "【 通知 】", "tag": "plain_text"}},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ requests.post(url, headers=headers, data=json.dumps(payload))
|
|
|
+
|
|
|
+
|
|
|
+def monitor():
|
|
|
+ """
|
|
|
+ 监测 redis 中数据
|
|
|
+ """
|
|
|
+ counts_info = {
|
|
|
+ "罗情": True,
|
|
|
+ "余海涛": True,
|
|
|
+ "范军": True,
|
|
|
+ "鲁涛": True
|
|
|
+ }
|
|
|
+ keys = {"352": "余海涛", "353": "罗情", "53": "范军", "51": "鲁涛"}
|
|
|
+ now = datetime.datetime.now().time()
|
|
|
+ start_alert_time = datetime.time(10)
|
|
|
+ end_alert_time = datetime.time(20, 30)
|
|
|
+ while True:
|
|
|
+ if start_alert_time <= now <= end_alert_time:
|
|
|
+ try:
|
|
|
+ R = RedisClient()
|
|
|
+ if R.connect():
|
|
|
+ for key in keys:
|
|
|
+ count = R.select(key)
|
|
|
+ if count:
|
|
|
+ OO = int(count.decode("utf-8"))
|
|
|
+ name = keys[key]
|
|
|
+ if OO >= 300 and counts_info[name]:
|
|
|
+ bot(name)
|
|
|
+ counts_info[name] = False
|
|
|
+ except Exception as e:
|
|
|
+ pass
|
|
|
+ # 查询一次之后等待 60 s
|
|
|
+ time.sleep(60)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ schedule.every().day.at("08:00").do(monitor)
|
|
|
+ while True:
|
|
|
+ schedule.run_pending()
|
|
|
+ time.sleep(60)
|