소스 검색

update published_articles_monitor improve

luojunhui 5 달 전
부모
커밋
598031dae8
2개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 19 2
      published_articles_monitor.py
  2. 1 1
      sh/published_articles_monitor.sh

+ 19 - 2
published_articles_monitor.py

@@ -1,8 +1,13 @@
+"""
+监测已发布文章
+"""
+
 from datetime import datetime
 from argparse import ArgumentParser
 from concurrent.futures import ThreadPoolExecutor
 
 from tqdm import tqdm
+from applications import bot
 from applications.db import DatabaseConnector
 from applications.const import updatePublishedMsgTaskConst
 from applications import WeixinSpider
@@ -28,10 +33,22 @@ def monitor_article(article):
                 VALUES 
                 (%s, %s, %s, %s, %s, %s);
                 """
-            long_articles_db_client.save(
+            affected_rows = long_articles_db_client.save(
                 query=insert_sql,
                 params=(gh_id, account_name, title, wx_sn, publish_date, error_detail),
             )
+            if affected_rows:
+                bot(
+                    title="文章违规告警",
+                    detail={
+                        "account_name": account_name,
+                        "gh_id": gh_id,
+                        "title": title,
+                        "wx_sn": wx_sn,
+                        "publish_date": publish_date,
+                        "error_detail": error_detail,
+                    }
+                )
     except Exception as e:
         print(e)
 
@@ -45,7 +62,7 @@ def get_article_list(run_date):
         run_date = datetime.today().strftime("%Y-%m-%d")
 
     monitor_start_timestamp = (
-        int(datetime.strptime(run_date, "%Y-%m-%d").timestamp()) - const.MONITOR_PERIOD
+            int(datetime.strptime(run_date, "%Y-%m-%d").timestamp()) - const.MONITOR_PERIOD
     )
     select_sql = f"""
         SELECT ghId, accountName, title, ContentUrl, wx_sn, from_unixtime(publish_timestamp) AS publish_timestamp

+ 1 - 1
sh/published_articles_monitor.sh

@@ -13,4 +13,4 @@ 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 &
+nohup python3 published_articles_monitor.py >> "${LOG_FILE}" 2>&1 &