소스 검색

add server account monitor

luojunhui 3 주 전
부모
커밋
377cc6ad90
2개의 변경된 파일16개의 추가작업 그리고 14개의 파일을 삭제
  1. 1 0
      fwh_data_manager.py
  2. 15 14
      tasks/data_tasks/fwh_data_recycle.py

+ 1 - 0
fwh_data_manager.py

@@ -6,6 +6,7 @@ if __name__ == '__main__':
     # 1. 从 aigc 获取数据
     fwh_group_publish_record_manager = FwhGroupPublishRecordManager()
     fwh_group_publish_record_manager.deal()
+    fwh_group_publish_record_manager.monitor()
 
     # 2. 保存数据到数据库
     save_fwh_data_to_database = SaveFwhDataToDatabase()

+ 15 - 14
tasks/data_tasks/fwh_data_recycle.py

@@ -50,10 +50,13 @@ class FwhDataRecycle:
         fetch_query = f"""
             select account_name from long_articles_group_send_result where gh_id = %s limit 1;
         """
-        fetch_response = self.long_articles_client.fetch(fetch_query, cursor_type=DictCursor, params=(gh_id,))
+        fetch_response = self.long_articles_client.fetch(
+            fetch_query, cursor_type=DictCursor, params=(gh_id,)
+        )
         account_name = fetch_response[0]["account_name"] if fetch_response else None
         return account_name
 
+
 class FwhGroupPublishRecordManager(FwhDataRecycle):
 
     def get_published_articles(self):
@@ -158,22 +161,26 @@ class FwhGroupPublishRecordManager(FwhDataRecycle):
                 where publish_date = %s
                 group by account_name, gh_id; 
             """
-            publish_records = self.long_articles_client.fetch(query=sql, cursor_type=DictCursor, params=(date_string,))
+            publish_records = self.long_articles_client.fetch(
+                query=sql, cursor_type=DictCursor, params=(date_string,)
+            )
             self.feishu_robot.bot(
                 title=f"{date_string}服务号发文记录",
                 mention=False,
                 detail=publish_records,
-                env="server_account_publish_monitor"
+                env="server_account_publish_monitor",
             )
 
-            publish_account_id_set = set([i['gh_id'] for i in publish_records])
+            publish_account_id_set = set([i["gh_id"] for i in publish_records])
             for account_id in account_list:
                 if account_id not in publish_account_id_set:
                     account_name = self.get_server_account_name(account_id)
-                    do_not_publish_account.append({
-                        "account_name": account_name,
-                        "gh_id": account_id,
-                    })
+                    do_not_publish_account.append(
+                        {
+                            "account_name": account_name,
+                            "gh_id": account_id,
+                        }
+                    )
 
             if do_not_publish_account:
                 self.feishu_robot.bot(
@@ -183,7 +190,6 @@ class FwhGroupPublishRecordManager(FwhDataRecycle):
                 )
 
 
-
 class SaveFwhDataToDatabase(FwhDataRecycle):
 
     def update_article_read_cnt(self, wx_sn, new_read_cnt):
@@ -365,8 +371,3 @@ class FwhDataExportTemp(FwhDataRecycle):
                     print(f"article {article['ContentUrl']} is not available, skip it")
         df = pd.DataFrame(L)
         df.to_csv("temp2.csv", index=False)
-
-
-if __name__ == "__main__":
-    w = FwhGroupPublishRecordManager()
-    w.monitor('2025-06-21')