Browse Source

限流账号监测

luojunhui 3 months ago
parent
commit
22c9dd0c18

+ 6 - 2
applications/tasks/cold_start_tasks/article_pool/article_pool_cold_start_strategy.py

@@ -69,9 +69,13 @@ class ArticlePoolColdStartStrategy(ArticlePoolColdStartConst):
                         self.TITLE_NOT_SENSITIVE,
                         self.INIT_STATUS,
                         # self.READ_TIMES_THRESHOLD,
-                        self.CATEGORY_CONFIG_MAP.get(category, self.READ_TIMES_THRESHOLD).get("read_times_threshold", self.READ_TIMES_THRESHOLD),
+                        self.CATEGORY_CONFIG_MAP.get(
+                            category, self.READ_TIMES_THRESHOLD
+                        ).get("read_times_threshold", self.READ_TIMES_THRESHOLD),
                         # self.READ_THRESHOLD,
-                        self.CATEGORY_CONFIG_MAP.get(category, self.READ_THRESHOLD).get("read_threshold", self.READ_THRESHOLD),
+                        self.CATEGORY_CONFIG_MAP.get(category, self.READ_THRESHOLD).get(
+                            "read_threshold", self.READ_THRESHOLD
+                        ),
                         self.INIT_STATUS,
                     ),
                 )

+ 1 - 1
applications/tasks/cold_start_tasks/article_pool/article_pool_filter_strategy.py

@@ -25,7 +25,7 @@ class ArticlePoolFilterStrategy(ArticlePoolColdStartConst):
         filter_df = dedup_df[
             (dedup_df["title"].str.len() <= self.TITLE_LENGTH_MAX)
             & (dedup_df["title"].str.len() >= self.TITLE_LENGTH_LIMIT)
-            ]
+        ]
         length_level1 = filter_df.shape[0]
 
         # 通过敏感词过滤

+ 27 - 14
applications/tasks/monitor_tasks/limited_account_analysis.py

@@ -3,14 +3,15 @@ import json
 from datetime import datetime, timedelta
 from applications.api import feishu_sheet, feishu_robot
 
+
 class LimitedAccountAnalysisConst:
     FIRST_POSITION = 1
     LIMIT_THRESHOLD = 0.2
     LIMIT_READ_AVG = 100
 
-    TABLE_ID = 'MqkxwleLFiNOwHkU3crcXpWlnfe'
-    DETAIL_SHEET_ID = '6fa679'
-    SUMMARY_SHEET_ID = 'uvli3P'
+    TABLE_ID = "MqkxwleLFiNOwHkU3crcXpWlnfe"
+    DETAIL_SHEET_ID = "6fa679"
+    SUMMARY_SHEET_ID = "uvli3P"
 
 
 class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
@@ -27,7 +28,15 @@ class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
             FROM datastat_sort_strategy
             WHERE date_str =  %s AND position = %s AND read_rate < %s AND avg_view_count >= %s;
         """
-        account_detail = await self.pool.async_fetch(query=query, params=(date_str, self.FIRST_POSITION, self.LIMIT_THRESHOLD, self.LIMIT_READ_AVG))
+        account_detail = await self.pool.async_fetch(
+            query=query,
+            params=(
+                date_str,
+                self.FIRST_POSITION,
+                self.LIMIT_THRESHOLD,
+                self.LIMIT_READ_AVG,
+            ),
+        )
         return account_detail
 
     async def get_limited_account_summary(self, date_str):
@@ -50,13 +59,16 @@ class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
                 date_str,
                 COALESCE(account_mode, '公众号投流');
         """
-        account_summary = await self.pool.async_fetch(query=query, params=(self.LIMIT_THRESHOLD, self.FIRST_POSITION, date_str))
+        account_summary = await self.pool.async_fetch(
+            query=query, params=(self.LIMIT_THRESHOLD, self.FIRST_POSITION, date_str)
+        )
         return account_summary
 
     async def insert_into_detail_table(self, detail_data):
         insert_array = []
         for row in detail_data:
-            insert_array.append([
+            insert_array.append(
+                [
                     row["date_str"],
                     row["account_mode"],
                     row["account_source"],
@@ -78,7 +90,8 @@ class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
     async def insert_into_summary_table(self, summary_data):
         insert_array = []
         for row in summary_data:
-            insert_array.append([
+            insert_array.append(
+                [
                     row["date_str"],
                     row["account_mode_label"],
                     row["limit_fans"],
@@ -89,31 +102,31 @@ class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
         await feishu_sheet.prepend_value(
             sheet_token=self.TABLE_ID,
             sheet_id=self.SUMMARY_SHEET_ID,
-            ranges=f"A2:E{2+len(summary_data)}",
+            ranges=f"A2:E{2 + len(summary_data)}",
             values=insert_array,
         )
 
     async def deal(self, date_string: str = None) -> None:
         """处理受限账号分析任务
-        
+
         Args:
             date_string: 日期字符串,格式为YYYYMMDD、YYYY-MM-DD或YYYY/MM/DD
         """
         # 如果没有提供日期,默认使用昨天
         if not date_string:
             date_string = (datetime.now() - timedelta(days=1)).strftime("%Y%m%d")
-        
+
         # 统一日期格式为YYYYMMDD
         date_string = date_string.replace("-", "").replace("/", "")
-        
+
         # 验证日期格式
         if len(date_string) != 8 or not date_string.isdigit():
             raise ValueError(f"无效的日期格式: {date_string},请使用YYYYMMDD格式")
-        
+
         try:
             detail_data = await self.get_limited_account_detail(date_str=date_string)
             summary_data = await self.get_limited_account_summary(date_str=date_string)
-            
+
             # 如果有数据才打印,避免空数据输出
             if detail_data:
                 await self.insert_into_detail_table(detail_data)
@@ -126,4 +139,4 @@ class LimitedAccountAnalysisTask(LimitedAccountAnalysisConst):
                 print(f"在 {date_string} 没有找到受限账号摘要数据")
         except Exception as e:
             print(f"处理受限账号分析时出错: {e}")
-            raise
+            raise