init repo
This commit is contained in:
52
app/data/factory.py
Normal file
52
app/data/factory.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Data router factory — assembles the router with all available sources."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from .router import DataRouter
|
||||
from .sources.akshare_source import AKShareSource
|
||||
from .sources.worldbank_source import WorldBankSource
|
||||
from .sources.gpt_researcher_source import GPTResearcherSource
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_data_router() -> DataRouter:
|
||||
"""Create a DataRouter with all available data sources.
|
||||
|
||||
Priority order (lower = tried first):
|
||||
10 AKShare — free, fast, covers Chinese macro/industry
|
||||
20 World Bank — free, global macro
|
||||
90 GPT Researcher — universal fallback (web research)
|
||||
|
||||
Future additions:
|
||||
30 巨潮资讯 — free tier, Chinese public companies
|
||||
40 天眼查 API — paid, company data
|
||||
50 Choice API — paid, financial data
|
||||
60 Statista API — paid, global industry stats
|
||||
70 FRED API — free, US macro
|
||||
80 UN Comtrade — free, global trade
|
||||
"""
|
||||
router = DataRouter()
|
||||
|
||||
# --- Free tier (always available) ---
|
||||
router.register(AKShareSource(), priority=10)
|
||||
router.register(WorldBankSource(), priority=20)
|
||||
|
||||
# --- Universal fallback ---
|
||||
router.register(GPTResearcherSource(), priority=90)
|
||||
|
||||
logger.info(f"[data_factory] created router with {len(router.sources)} sources")
|
||||
return router
|
||||
|
||||
|
||||
# Singleton
|
||||
_router: DataRouter | None = None
|
||||
|
||||
|
||||
def get_data_router() -> DataRouter:
|
||||
global _router
|
||||
if _router is None:
|
||||
_router = create_data_router()
|
||||
return _router
|
||||
Reference in New Issue
Block a user