refactor: cleanup dead code, fix model confusion, streamline CLI
- Remove 3 dead modules: academic/, wechat/, social/ (merged into engines/) - Remove 4 stale news scripts (tech_news.py, wallstreetcn.py, cls.py, rss.py) - scripts/core/base.py: canonical SearchResult + BaseEngine (was in engines/base.py) - scripts/engines/base.py: re-exports from core.base for compatibility - scripts/engines/news_engine.py: Bing News + RSS unified (was in scripts/news/rss.py) - scripts/engines/academic_engine.py: ArXiv + CrossRef unified (was in scripts/academic/arxiv.py) - scripts/cli.py: complete rewrite — 10 commands (search/web/news/academic/wechat/social/rss/baidu/health/sources) - scripts/unified_search.py: clean async Python API (was a stub) - ws.py: lightweight launcher - README.md + SKILL.md: updated to reflect actual 15+ engines - All EngineResult → SearchResult - All engines return list[SearchResult]
This commit is contained in:
1 parent
e20478fcbd
commit
c077a7ae40
31 files changed
+1188
-3148
No files matched your search
+3
-55
@@ -6,59 +6,7 @@ from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from scripts.core.execution_log import execution_log
|
||||
# Re-export SearchResult/BaseEngine from scripts.core.base for engine code compatibility
|
||||
from scripts.core.base import BaseEngine, SearchResult
|
||||
|
||||
|
||||
@dataclass
|
||||
class EngineResult:
|
||||
"""Unified result from any engine."""
|
||||
title: str
|
||||
url: str
|
||||
snippet: str = ""
|
||||
source: str = ""
|
||||
category: str = "" # "general" | "news" | "academic" | "github"
|
||||
published: str = ""
|
||||
extra: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
class BaseEngine(ABC):
|
||||
"""Base class for all search engines.
|
||||
|
||||
Automatically tracks execution timing and errors via execution_log.
|
||||
"""
|
||||
|
||||
name: str = "unknown"
|
||||
timeout: float = 10.0
|
||||
|
||||
def __init__(self, timeout: float = 10.0):
|
||||
self.timeout = timeout
|
||||
|
||||
async def search_with_log(
|
||||
self, query: str, max_results: int = 10, **kwargs
|
||||
) -> list[EngineResult]:
|
||||
"""Search with automatic execution logging.
|
||||
|
||||
Subclasses override `search()`, not this method.
|
||||
"""
|
||||
with execution_log.track(self.name, "search", query=query) as ctx:
|
||||
results = await self.search(query, max_results=max_results, **kwargs)
|
||||
ctx.result_count = len(results)
|
||||
return results
|
||||
|
||||
@abstractmethod
|
||||
async def search(self, query: str, max_results: int = 10,
|
||||
**kwargs) -> list[EngineResult]:
|
||||
...
|
||||
|
||||
async def health(self) -> dict:
|
||||
"""Quick connectivity check."""
|
||||
with execution_log.track(self.name, "health") as ctx:
|
||||
try:
|
||||
results = await self.search("test", max_results=1)
|
||||
ctx.result_count = len(results)
|
||||
return {"name": self.name, "status": "ok", "count": len(results)}
|
||||
except Exception as e:
|
||||
ctx.success = False
|
||||
ctx.error = str(e)
|
||||
ctx.error_type = type(e).__name__
|
||||
return {"name": self.name, "status": "fail", "error": str(e)}
|
||||
__all__ = ["BaseEngine", "SearchResult"]
|
||||
Reference in new issue
Block a user