run_weixinzhishu_bot.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/4/21
  4. import datetime
  5. import os
  6. import sys
  7. import time
  8. sys.path.append(os.getcwd())
  9. from common.common import Common
  10. from common.feishu import Feishu
  11. class WeixinzhishuBot:
  12. @classmethod
  13. def search_key_bot(cls, log_type, crawler):
  14. if (datetime.datetime.now().hour == 11 and datetime.datetime.now().minute >= 30)\
  15. or (datetime.datetime.now().hour == 13 and datetime.datetime.now().minute >= 30):
  16. Common.logger(log_type, crawler).info("开始检测微信指数 Search_Key 抓取状态")
  17. sheet = Feishu.get_values_batch(log_type, crawler, sheetid="sVL74k")
  18. while True:
  19. if sheet is None:
  20. continue
  21. first_key_time_str = sheet[1][0]
  22. if first_key_time_str is None:
  23. Feishu.bot(log_type, crawler, "微信指数 Search_Key is None ~")
  24. time.sleep(60*10)
  25. continue
  26. first_key_time_stamp = int(time.mktime(time.strptime(first_key_time_str, "%Y-%m-%d %H:%M:%S")))
  27. if int(time.time()) - first_key_time_stamp < 60*3:
  28. Common.logger(log_type, crawler).info("微信指数 Search_Key 正常")
  29. time.sleep(60*10)
  30. else:
  31. Feishu.bot(log_type, crawler, "微信指数 Search_Key 过期啦 ~")
  32. return
  33. else:
  34. Common.logger(log_type, crawler).info("微信指数 Search_Key 抓取状态检测结束\n")
  35. if __name__ == "__main__":
  36. WeixinzhishuBot.search_key_bot("bot", "weixinzhishu")
  37. pass