refactor(06-01): update platform adapters to use standard imports

- Remove sys.path manipulation from bilibili.py and zhihu.py
- Use standard imports from kb_workflow.metadata
- Remove try/except wrappers around imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 00:01:22 +08:00
parent a4a7454cd0
commit 98f8ec2e27
2 changed files with 7 additions and 40 deletions
+6 -21
View File
@@ -11,17 +11,11 @@ from typing import Dict, Any, Optional
from datetime import datetime
import re
import asyncio
import sys
from pathlib import Path
# Add kb-zhihu-metadata to path for import
_kb_zhihu_path = Path(__file__).parent.parent.parent / "kb-zhihu-metadata"
if str(_kb_zhihu_path) not in sys.path:
sys.path.insert(0, str(_kb_zhihu_path))
from kb_pipeline.platforms.base import PlatformAdapter
from kb_pipeline.errors import AuthError
from kb_pipeline.config import get_settings
from kb_workflow.metadata.zhihu_extractor import ZhihuPlaywrightExtractor
class ZhihuAdapter(PlatformAdapter):
@@ -89,24 +83,15 @@ class ZhihuAdapter(PlatformAdapter):
def _get_extractor(self):
"""Get or create ZhihuPlaywrightExtractor instance.
Lazy import to avoid dependency issues when kb-zhihu-metadata is not installed.
Returns:
ZhihuPlaywrightExtractor instance
"""
if self._extractor is None:
try:
from zhihu_extractor import ZhihuPlaywrightExtractor
self._extractor = ZhihuPlaywrightExtractor(
headless=self.headless,
timeout=self.timeout,
cookie=self.cookie
)
except ImportError as e:
raise ImportError(
"kb-zhihu-metadata module not found. "
"Please ensure kb-zhihu-metadata directory exists."
) from e
self._extractor = ZhihuPlaywrightExtractor(
headless=self.headless,
timeout=self.timeout,
cookie=self.cookie
)
return self._extractor
def _extract_with_playwright(self, url: str) -> Optional[Dict[str, Any]]: