Selaa lähdekoodia

服务号报警优化

luojunhui 2 päivää sitten
vanhempi
commit
a4811e419f
2 muutettua tiedostoa jossa 21 lisäystä ja 4 poistoa
  1. 3 3
      fwh_data_manager.py
  2. 18 1
      tasks/data_tasks/fwh_data_recycle.py

+ 3 - 3
fwh_data_manager.py

@@ -12,7 +12,7 @@ if __name__ == '__main__':
     fwh_group_publish_monitor = FwhGroupPublishMonitor()
     fwh_group_publish_monitor = FwhGroupPublishMonitor()
     fwh_group_publish_monitor.deal()
     fwh_group_publish_monitor.deal()
 
 
-    # # # 3. 保存数据到数据库
-    # save_fwh_data_to_database = SaveFwhDataToDatabase()
-    # save_fwh_data_to_database.deal()
+    # 3. 保存数据到数据库
+    save_fwh_data_to_database = SaveFwhDataToDatabase()
+    save_fwh_data_to_database.deal()
 
 

+ 18 - 1
tasks/data_tasks/fwh_data_recycle.py

@@ -71,6 +71,7 @@ class FwhDataRecycle:
         group_id: str,
         group_id: str,
         illegal_msg: str,
         illegal_msg: str,
         publish_date: str,
         publish_date: str,
+        article_title: str,
     ):
     ):
         self.feishu_robot.bot(
         self.feishu_robot.bot(
             title="服务号文章违规告警,请前往微信公众平台处理",
             title="服务号文章违规告警,请前往微信公众平台处理",
@@ -80,6 +81,7 @@ class FwhDataRecycle:
                 "group_id": group_id,
                 "group_id": group_id,
                 "illegal_msg": illegal_msg,
                 "illegal_msg": illegal_msg,
                 "publish_date": str(publish_date),
                 "publish_date": str(publish_date),
+                "article_title": article_title,
             },
             },
             env="server_account_publish_monitor",
             env="server_account_publish_monitor",
         )
         )
@@ -207,7 +209,7 @@ class SaveFwhDataToDatabase(FwhDataRecycle):
     def get_stat_published_articles(self, gh_id):
     def get_stat_published_articles(self, gh_id):
         earliest_timestamp = int(time.time()) - self.STAT_PERIOD
         earliest_timestamp = int(time.time()) - self.STAT_PERIOD
         fetch_query = f"""
         fetch_query = f"""
-            select publish_date, account_name, gh_id, user_group_id, url, publish_timestamp
+            select publish_date, account_name, gh_id, user_group_id, url, publish_timestamp, content_id
             from long_articles_group_send_result
             from long_articles_group_send_result
             where gh_id = %s and recycle_status = %s and create_time > %s;
             where gh_id = %s and recycle_status = %s and create_time > %s;
         """
         """
@@ -230,6 +232,7 @@ class SaveFwhDataToDatabase(FwhDataRecycle):
             user_group_id = article["user_group_id"]
             user_group_id = article["user_group_id"]
             url = article["url"]
             url = article["url"]
             publish_date = article["publish_date"]
             publish_date = article["publish_date"]
+            content_id = article["content_id"]
             # get article detail info with spider
             # get article detail info with spider
 
 
             try:
             try:
@@ -238,12 +241,26 @@ class SaveFwhDataToDatabase(FwhDataRecycle):
                 )
                 )
                 response_code = article_detail_info["code"]
                 response_code = article_detail_info["code"]
                 if response_code == self.ARTICLE_ILLEGAL_CODE:
                 if response_code == self.ARTICLE_ILLEGAL_CODE:
+                    query = """
+                        SELECT article_title FROM long_articles_text WHERE content_id = %s;
+                    """
+                    article_title = self.long_articles_client.fetch(
+                        query=query,
+                        cursor_type=DictCursor,
+                        params=(content_id,),
+                    )
+                    if article_title:
+                        article_title = article_title[0]["article_title"]
+                    else:
+                        article_title = content_id
+
                     self.illegal_article_bot(
                     self.illegal_article_bot(
                         account_name=account_name,
                         account_name=account_name,
                         gh_id=gh_id,
                         gh_id=gh_id,
                         group_id=user_group_id,
                         group_id=user_group_id,
                         illegal_msg=article_detail_info["msg"],
                         illegal_msg=article_detail_info["msg"],
                         publish_date=publish_date,
                         publish_date=publish_date,
+                        article_title=article_title,
                     )
                     )
 
 
                 time.sleep(1)
                 time.sleep(1)