Browse Source

优化更新每日发送文章code

luojunhui 4 tháng trước cách đây
mục cha
commit
2c4fe234b2
2 tập tin đã thay đổi với 41 bổ sung9 xóa
  1. 16 0
      sh/published_articles_monitor.sh
  2. 25 9
      updatePublishedMsgDaily.py

+ 16 - 0
sh/published_articles_monitor.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# 获取当前日期,格式为 YYYY-MM-DD
+CURRENT_DATE=$(date +%F)
+
+# 日志文件路径,包含日期
+LOG_FILE="/root/luojunhui/logs/article_monitor_task_log_$CURRENT_DATE.txt"
+
+# 重定向整个脚本的输出到带日期的日志文件
+exec >> "$LOG_FILE" 2>&1
+
+cd /root/luojunhui/LongArticlesJob
+source /root/miniconda3/etc/profile.d/conda.sh
+conda activate tasks
+
+nohup python3 updatePublishedMsgDaily.py --run_task monitor >> "${LOG_FILE}" 2>&1 &

+ 25 - 9
updatePublishedMsgDaily.py

@@ -619,18 +619,34 @@ def monitor():
         title = article[2]
         url = article[3]
         wx_sn = article[4]
-        response = spider.get_article_text(url)
-        response_code = response['code']
-        if response_code == const.ARTICLE_ILLEGAL_CODE:
-            bot(
-                title="文章违规告警",
-                detail={
+        try:
+            response = spider.get_article_text(url)
+            response_code = response['code']
+            if response_code == const.ARTICLE_ILLEGAL_CODE:
+                bot(
+                    title="文章违规告警",
+                    detail={
+                        "ghId": gh_id,
+                        "accountName": account_name,
+                        "title": title,
+                        "wx_sn": wx_sn
+                    },
+                    mention=False
+                )
+        except Exception as e:
+            error_msg = traceback.format_exc()
+            log(
+                task="monitor",
+                function="monitor",
+                message="请求文章详情失败",
+                data={
                     "ghId": gh_id,
                     "accountName": account_name,
                     "title": title,
-                    "wx_sn": wx_sn
-                },
-                mention=False
+                    "wx_sn": wx_sn,
+                    "error": e,
+                    "msg": error_msg
+                }
             )