Forráskód Böngészése

1. 飞书新增读取数据功能
2. 公众号爬虫增加账号获取功能
3. 过滤公众号

luojunhui 3 hete
szülő
commit
16ec22bf26

+ 1 - 0
app/domains/data_recycle_tasks/recycle_daily_publish_articles.py

@@ -103,6 +103,7 @@ class Const:
         "gh_9f8dc5b0c74e",
         "gh_7e5818b2dd83",
         "gh_0c89e11f8bf3",
+        "gh_7051e5ad35bb"
     }
 
     STAT_PERIOD = 3 * 24 * 3600

+ 23 - 0
app/infra/crawler/wechat/gzh_spider.py

@@ -132,3 +132,26 @@ async def weixin_search(keyword: str, page="1") -> dict | None:
         )
         return None
     return response
+
+@retry(**retry_desc)
+async def get_account_from_url(article_url) -> dict | None:
+    """通过文章链接获取公众号账号信息
+
+    Args:
+        article_url: 文章链接
+    """
+    url = f"{base_url}/account_info"
+    payload = json.dumps({"content_link": article_url})
+    print(f"INFO: Reading page: {article_url}")
+    try:
+        async with AsyncHttpClient(timeout=120) as http_client:
+            response = await http_client.post(url=url, headers=headers, data=payload)
+    except Exception as e:
+        log(
+            task="get_account_from_url",
+            function="get_account_from_url",
+            message=f"API请求失败: {e}",
+            data={"article_url": article_url},
+        )
+        return None
+    return response

+ 32 - 0
app/infra/external/feishu.py

@@ -86,6 +86,38 @@ class Feishu:
 
 
 class FeishuSheetApi(Feishu):
+    async def read_sheet_range(
+        self, spreadsheet_token: str, range_str: str
+    ) -> list[list]:
+        """读取电子表格指定范围的数据。
+
+        Args:
+            spreadsheet_token: 电子表格 token
+            range_str: 查询范围,格式为 "<sheet_id>!<开始位置>:<结束位置>",如 "4d54bd!A1:K358"
+
+        Returns:
+            数据二维数组。失败或无数据时返回空列表。
+        """
+        if not self.token:
+            await self.fetch_token()
+
+        url = f"https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/{spreadsheet_token}/values/{range_str}"
+        print(self.token)
+        headers = {
+            "Authorization": f"Bearer {self.token}",
+            "Content-Type": "application/json; charset=utf-8",
+        }
+        async with AsyncHttpClient() as client:
+            response = await client.get(url=url, headers=headers)
+
+        if response.get("code", 0) != 0:
+            print(f"飞书读取表格失败: {response.get('msg', 'unknown error')}")
+            return []
+
+        data = response.get("data", {})
+        value_range = data.get("valueRange", {})
+        return value_range.get("values", [])
+    
     async def prepend_value(self, sheet_token, sheet_id, ranges, values):
         insert_value_url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/{}/values_prepend".format(
             sheet_token