ソースを参照

Merge branch 'wangkun'
add weixinzhishu_bot

wangkun 2 年 前
コミット
530c829711
3 ファイル変更63 行追加0 行削除
  1. 5 0
      common/feishu.py
  2. 15 0
      main/process.sh
  3. 43 0
      weixinzhishu/weixinzhishu_main/run_weixinzhishu_bot.py

+ 5 - 0
common/feishu.py

@@ -465,6 +465,11 @@ class Feishu:
                 sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnqhMRUGunIfGnGXMOBYiy4K?sheet=JpgyAv"
                 users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangkun")) + "></at> <at id=" + str(
                     cls.get_userid(log_type, crawler, "muxinyi")) + "></at>\n"
+            elif crawler == "weixinzhishu":
+                content = "微信指数_Search_Key"
+                sheet_url = "https://w42nne6hzg.feishu.cn/sheets/shtcnqhMRUGunIfGnGXMOBYiy4K?sheet=sVL74k"
+                users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangkun")) + "></at> <at id=" + str(
+                    cls.get_userid(log_type, crawler, "muxinyi")) + "></at>\n"
 
             elif crawler == "xiaoniangao_hour":
                 content = "小年糕_小时级_已下载表"

+ 15 - 0
main/process.sh

@@ -251,6 +251,21 @@ else
   echo "$(date "+%Y-%m-%d %H:%M:%S") 岁岁年年迎福气小程序爬虫 进程状态正常" >> ${log_path}
 fi
 
+# 微信指数 bot
+echo "$(date "+%Y-%m-%d %H:%M:%S") 正在监测 微信指数 bot 爬虫 进程状态" >> ${log_path}
+ps -ef | grep "run_weixinzhishu_bot" | grep -v "grep"
+if [ "$?" -eq 1 ];then
+  echo "$(date "+%Y-%m-%d_%H:%M:%S") 异常停止,正在重启!" >> ${log_path}
+  if [ ${env} = "dev" ];then
+    cd ${piaoquan_crawler_dir} && sh main/scheduling_main.sh ./weixinzhishu/weixinzhishu_main/run_weixinzhishu_bot.py --log_type="bot" --crawler="weixinzhishu" --env="dev" weixinzhishu/logs/nohup-bot.log
+  else
+    cd ${piaoquan_crawler_dir} && /usr/bin/sh /data5/piaoquan_crawler/main/scheduling_main.sh ./weixinzhishu/weixinzhishu_main/run_weixinzhishu_bot.py --log_type="bot" --crawler="weixinzhishu" --env="prod"  weixinzhishu/logs/nohup-bot.log
+  fi
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 重启完成!" >> ${log_path}
+else
+  echo "$(date "+%Y-%m-%d %H:%M:%S") 微信指数 bot 爬虫 进程状态正常" >> ${log_path}
+fi
+
 
 # 删除日志
 echo "$(date "+%Y-%m-%d %H:%M:%S") 开始清理 5 天前的日志文件" >> ${log_path}

+ 43 - 0
weixinzhishu/weixinzhishu_main/run_weixinzhishu_bot.py

@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+# @Author: wangkun
+# @Time: 2023/4/21
+import datetime
+import os
+import sys
+import time
+sys.path.append(os.getcwd())
+from common.common import Common
+from common.feishu import Feishu
+
+
+class WeixinzhishuBot:
+    @classmethod
+    def search_key_bot(cls, log_type, crawler):
+        if (datetime.datetime.now().hour == 11 and datetime.datetime.now().minute >= 30)\
+                or (datetime.datetime.now().hour == 13 and datetime.datetime.now().minute >= 30):
+            Common.logger(log_type, crawler).info("开始检测微信指数 Search_Key 抓取状态")
+            sheet = Feishu.get_values_batch(log_type, crawler, sheetid="sVL74k")
+            while True:
+                if sheet is None:
+                    continue
+                first_key_time_str = sheet[1][0]
+                if first_key_time_str is None:
+                    Feishu.bot(log_type, crawler, "微信指数 Search_Key is None ~")
+                    time.sleep(60*10)
+                    continue
+
+                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:
+                    Common.logger(log_type, crawler).info("微信指数 Search_Key 正常")
+                    time.sleep(60*10)
+                else:
+                    Feishu.bot(log_type, crawler, "微信指数 Search_Key 过期啦 ~")
+                    return
+        else:
+            Common.logger(log_type, crawler).info("微信指数 Search_Key 抓取状态检测结束\n")
+
+
+if __name__ == "__main__":
+    WeixinzhishuBot.search_key_bot("bot", "weixinzhishu")
+
+    pass