소스 검색

删除 limit报警
把 bot 独立出来

罗俊辉 1 년 전
부모
커밋
bc61565607
1개의 변경된 파일21개의 추가작업 그리고 9개의 파일을 삭제
  1. 21 9
      changsha_bot.py

+ 21 - 9
changsha_bot.py

@@ -55,12 +55,6 @@ 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)
@@ -75,10 +69,19 @@ def monitor():
                         if count:
                             OO = int(count.decode("utf-8"))
                             name = keys[key]
-                            if OO >= 300 and counts_info[name]:
-                                bot(name)
-                                counts_info[name] = False
+                            redis_date_key = key + "-" + datetime.date.today().strftime("%Y%m%d")
+                            if R.select(redis_date_key):
+                                # 说明已经存储进去了, 不需要再报警了
+                                continue
+                            else:
+                                if OO > 300:
+                                    R.insert(redis_date_key, "already bot", 86400)
+                                    # print("超过了, 报警", name)
+                                    bot(name)
+                                else:
+                                    continue
             except Exception as e:
+                print(e)
                 pass
             # 查询一次之后等待 60 s
         time.sleep(60)
@@ -86,3 +89,12 @@ def monitor():
 
 if __name__ == '__main__':
     monitor()
+    # R = RedisClient()
+    # R.connect()
+    # # w = R.select("53-20240327")
+    # # print(w)
+    # R.delete("51-20240327")
+    # R.delete("53-20240327")
+    # R.delete("353-20240327")
+    # R.delete("352-20240327")
+