run_weixinzhishu_bot.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/4/21
  4. from datetime import date, datetime
  5. from workalendar.asia import China
  6. import warnings
  7. import os
  8. import sys
  9. import time
  10. sys.path.append(os.getcwd())
  11. from common.common import Common
  12. from common.feishu import Feishu
  13. class WeixinzhishuBot:
  14. @classmethod
  15. def check_workday(cls):
  16. warnings.simplefilter("ignore", UserWarning)
  17. # 创建中国日历对象
  18. cal = China()
  19. # 判断日期是否为法定节假日
  20. is_workday = cal.is_working_day(date.today())
  21. return is_workday
  22. @classmethod
  23. def search_key_bot(cls, log_type, crawler):
  24. Common.logger(log_type, crawler).info("开始检测微信指数 Search_Key 抓取状态")
  25. sheet = Feishu.get_values_batch(log_type, crawler, sheetid="sVL74k")
  26. if sheet is None:
  27. Common.logger(log_type, crawler).info(f"Search_Key_sheet:{sheet}\n")
  28. first_key_time_str = sheet[1][0]
  29. if first_key_time_str is None:
  30. if 13 >= datetime.now().hour >= 11 and datetime.now().minute >= 20:
  31. # Feishu.bot(log_type, crawler, "微信指数 Search_Key is None ~")
  32. time.sleep(60)
  33. first_key_time_stamp = int(time.mktime(time.strptime(first_key_time_str, "%Y-%m-%d %H:%M:%S")))
  34. if int(time.time()) - first_key_time_stamp >= 60*3:
  35. if cls.check_workday() is True and 13 >= datetime.now().hour >= 11 and datetime.now().minute >= 20:
  36. Feishu.bot(log_type, crawler, "微信指数 Search_Key 过期啦 ~")
  37. time.sleep(3600*2)
  38. else:
  39. Common.logger(log_type, crawler).info("微信指数 Search_Key 正常")
  40. Common.logger(log_type, crawler).info("微信指数 Search_Key 抓取状态检测结束\n")
  41. if __name__ == "__main__":
  42. WeixinzhishuBot.search_key_bot("bot", "weixinzhishu")
  43. pass