Explorar o código

Merge branch '2025-03-19-toutiao-crawler-add-sh' of luojunhui/LongArticlesJob into master

luojunhui hai 1 mes
pai
achega
ff15a34cc9
Modificáronse 2 ficheiros con 29 adicións e 0 borrados
  1. 3 0
      config/crontab_backup
  2. 26 0
      sh/run_toutiao_account_video_crawler.sh

+ 3 - 0
config/crontab_backup

@@ -1,3 +1,6 @@
+# 每天凌晨 4点,下午 4 点各执行一次头条视频抓取
+0 4,16 * * * bash /root/luojunhui/LongArticlesJob/sh/run_toutiao_account_video_crawler.sh
+
 # 每15分钟执行一次今日头条推荐流抓取
 */15 * * * * bash /root/luojunhui/LongArticlesJob/sh/run_toutiao_recommend.sh
 

+ 26 - 0
sh/run_toutiao_account_video_crawler.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# 获取当前日期,格式为 YYYY-MM-DD
+CURRENT_DATE=$(date +%F)
+
+# 日志文件路径,包含日期
+LOG_FILE="/root/luojunhui/logs/toutiao_account_video_crawler_task_log_$CURRENT_DATE.txt"
+
+# 重定向整个脚本的输出到带日期的日志文件
+exec >> "$LOG_FILE" 2>&1
+if pgrep -f "python3 toutiao_video_crawler.py" > /dev/null
+then
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - toutiao_video_crawler.py is running"
+else
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - trying to restart toutiao_video_crawler.py"
+    # 切换到指定目录
+    cd /root/luojunhui/LongArticlesJob
+
+    # 激活 Conda 环境
+    source /root/miniconda3/etc/profile.d/conda.sh
+    conda activate tasks
+
+    # 在后台运行 Python 脚本并重定向日志输出
+    nohup python3 toutiao_video_crawler.py >> "${LOG_FILE}" 2>&1 &
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - successfully restarted toutiao_video_crawler.py"
+fi