Browse Source

文章退场代码,用 crontab 每天上午11:00执行

luojunhui 5 months ago
parent
commit
98660827f0
2 changed files with 34 additions and 0 deletions
  1. 8 0
      run_article_title_exit_v1.py
  2. 26 0
      sh/run_article_title_exit_v1.sh

+ 8 - 0
run_article_title_exit_v1.py

@@ -0,0 +1,8 @@
+"""
+@author: luojunhui
+"""
+from flow_pool.exit_article_with_title import main
+
+
+if __name__ == '__main__':
+    main()

+ 26 - 0
sh/run_article_title_exit_v1.sh

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