feat: add project acceptance collection service

This commit is contained in:
2026-08-19 15:28:14 +08:00
parent 175b38138e
commit 2da7f4f328
8 changed files with 1321 additions and 2 deletions

View File

@@ -78,6 +78,29 @@ def _post(
return data
def _get(path: str) -> dict[str, Any]:
url = f"{Config.CRAWLER_BASE_URL}{path}"
try:
response = CRAWLER_SESSION.get(url, timeout=Config.CRAWLER_TIMEOUT_SECONDS)
response.raise_for_status()
payload = response.json()
except requests.RequestException as exc:
raise CrawlerError(f"爬虫服务请求失败:{exc}") from exc
except ValueError as exc:
raise CrawlerError("爬虫服务返回的不是有效 JSON") from exc
if payload.get("code") != 200 or not payload.get("success", False):
raise CrawlerError(payload.get("msg") or "爬虫服务返回失败")
data = payload.get("data")
if not isinstance(data, dict):
raise CrawlerError("爬虫服务响应缺少 data")
return data
def get_wen_resources() -> dict[str, Any]:
"""查询当前可用 Cookie 和可立即下发截图的设备。"""
return _get("/api/v1/xhs/wen/resources")
def start_collection(mode: str, keywords: list[str]) -> dict[str, Any]:
"""深度任务走 sources轻度/常规任务走 overview。"""
@@ -113,3 +136,38 @@ def resume_collection(crawler_task_id: str) -> dict[str, Any]:
"""沿用原爬虫任务 ID从 framework 保存的检查点继续采集。"""
return _post(f"/api/v1/xhs/wen/tasks/{crawler_task_id}/resume", {})
def fetch_content_detail(note_url: str) -> dict[str, Any]:
"""按小红书笔记链接读取完整笔记详情。"""
return _post(
"/api/v1/fetch_content_detail",
{"plant": "xhs", "link": note_url},
retry_transient=True,
)
def schedule_xapi_screenshots(search_queries: list[str], device_count: int) -> dict[str, Any]:
"""向手机集群下发问一问关键词搜索与截图任务。"""
queries = normalize_collection_keywords(search_queries)
return _post(
"/api/v1/xhs/wen/xapi/schedule",
{"keywords": queries, "device_count": device_count},
retry_transient=False,
)
def collect_keyword_sources(keyword: str, credential_id: str | None = None) -> dict[str, Any]:
"""使用 sources 的完整 Cookie 池采集单个关键词。"""
normalized = normalize_collection_keywords([keyword])[0]
body: dict[str, Any] = {"keyword": normalized}
if credential_id:
body["credential_id"] = credential_id
return _post(
"/api/v1/xhs/wen/sources",
body,
retry_transient=False,
)