wangkun 1 рік тому
батько
коміт
ef449da7d0

+ 2 - 0
requirements.txt

@@ -28,3 +28,5 @@ selenium==4.9.1
 urllib3==1.26.9
 # pip3 install jieba
 jieba==0.42.1
+# pip3 install workalendar
+workalendar==17.0.0

+ 2 - 6
weixinzhishu/weixinzhishu_key/search_key_mac.py

@@ -13,7 +13,7 @@
     3.2 python ./weixinzhishu/weixinzhishu_main/search_key_mac.py
 4. 每 10 秒获取最新search_key,写入飞书: https://w42nne6hzg.feishu.cn/sheets/shtcnqhMRUGunIfGnGXMOBYiy4K?sheet=sVL74k
 """
-import datetime
+from datetime import datetime
 import json
 import os
 import sys
@@ -221,7 +221,7 @@ class SearchKey:
     @classmethod
     def main(cls, log_type, crawler):
         while True:
-            if 11 <= datetime.datetime.now().hour <= 14:
+            if 11 <= datetime.now().hour <= 14:
                 cls.write_wechat_key(log_type, crawler)
                 Common.logger(log_type, crawler).info('休眠10秒\n')
                 time.sleep(10)
@@ -231,9 +231,5 @@ class SearchKey:
 
 
 if __name__ == "__main__":
-    # SearchKey.start_wechat("search", "weixinzhishu")
-    # SearchKey.del_wechat_key("search", "weixinzhishu")
-    # SearchKey.write_wechat_key("search", "weixinzhishu")
-    # print(SearchKey.get_wechat_key("search", "weixinzhishu"))
     SearchKey.main("search", "weixinzhishu")
     pass

+ 14 - 4
weixinzhishu/weixinzhishu_main/run_weixinzhishu_bot.py

@@ -1,7 +1,9 @@
 # -*- coding: utf-8 -*-
 # @Author: wangkun
 # @Time: 2023/4/21
-import datetime
+from datetime import date, datetime
+from workalendar.asia import China
+import warnings
 import os
 import sys
 import time
@@ -11,6 +13,15 @@ from common.feishu import Feishu
 
 
 class WeixinzhishuBot:
+    @classmethod
+    def check_workday(cls):
+        warnings.simplefilter("ignore", UserWarning)
+        # 创建中国日历对象
+        cal = China()
+        # 判断日期是否为法定节假日
+        is_workday = cal.is_working_day(date.today())
+        return is_workday
+
     @classmethod
     def search_key_bot(cls, log_type, crawler):
         Common.logger(log_type, crawler).info("开始检测微信指数 Search_Key 抓取状态")
@@ -21,13 +32,13 @@ class WeixinzhishuBot:
 
         first_key_time_str = sheet[1][0]
         if first_key_time_str is None:
-            if 13 >= datetime.datetime.now().hour >= 11 and datetime.datetime.now().minute >= 20:
+            if 13 >= datetime.now().hour >= 11 and datetime.now().minute >= 20:
                 # Feishu.bot(log_type, crawler, "微信指数 Search_Key is None ~")
                 time.sleep(60)
 
         first_key_time_stamp = int(time.mktime(time.strptime(first_key_time_str, "%Y-%m-%d %H:%M:%S")))
         if int(time.time()) - first_key_time_stamp >= 60*3:
-            if 13 >= datetime.datetime.now().hour >= 11 and datetime.datetime.now().minute >= 20:
+            if cls.check_workday() is True and 13 >= datetime.now().hour >= 11 and datetime.now().minute >= 20:
                 Feishu.bot(log_type, crawler, "微信指数 Search_Key 过期啦 ~")
                 time.sleep(3600*2)
         else:
@@ -37,5 +48,4 @@ class WeixinzhishuBot:
 
 if __name__ == "__main__":
     WeixinzhishuBot.search_key_bot("bot", "weixinzhishu")
-
     pass