Parcourir la source

update published_articles_monitor improve

luojunhui il y a 11 mois
Parent
commit
598031dae8
2 fichiers modifiés avec 20 ajouts et 3 suppressions
  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 datetime import datetime
 from argparse import ArgumentParser
 from argparse import ArgumentParser
 from concurrent.futures import ThreadPoolExecutor
 from concurrent.futures import ThreadPoolExecutor
 
 
 from tqdm import tqdm
 from tqdm import tqdm
+from applications import bot
 from applications.db import DatabaseConnector
 from applications.db import DatabaseConnector
 from applications.const import updatePublishedMsgTaskConst
 from applications.const import updatePublishedMsgTaskConst
 from applications import WeixinSpider
 from applications import WeixinSpider
@@ -28,10 +33,22 @@ def monitor_article(article):
                 VALUES 
                 VALUES 
                 (%s, %s, %s, %s, %s, %s);
                 (%s, %s, %s, %s, %s, %s);
                 """
                 """
-            long_articles_db_client.save(
+            affected_rows = long_articles_db_client.save(
                 query=insert_sql,
                 query=insert_sql,
                 params=(gh_id, account_name, title, wx_sn, publish_date, error_detail),
                 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:
     except Exception as e:
         print(e)
         print(e)
 
 
@@ -45,7 +62,7 @@ def get_article_list(run_date):
         run_date = datetime.today().strftime("%Y-%m-%d")
         run_date = datetime.today().strftime("%Y-%m-%d")
 
 
     monitor_start_timestamp = (
     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_sql = f"""
         SELECT ghId, accountName, title, ContentUrl, wx_sn, from_unixtime(publish_timestamp) AS publish_timestamp
         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
 source /root/miniconda3/etc/profile.d/conda.sh
 conda activate tasks
 conda activate tasks
 
 
-nohup python3 updatePublishedMsgDaily.py --run_task monitor >> "${LOG_FILE}" 2>&1 &
+nohup python3 published_articles_monitor.py >> "${LOG_FILE}" 2>&1 &