poller.py 827 B

123456789101112131415161718192021
  1. from __future__ import annotations
  2. from typing import Any, Dict
  3. from news_mcp.config import CLUSTERS_TTL_HOURS, DB_PATH
  4. from news_mcp.dedup.cluster import dedup_and_cluster_articles
  5. from news_mcp.enrichment.enrich import enrich_cluster
  6. from news_mcp.sources.rss_breakingthenews import fetch_breakingthenews_articles
  7. from news_mcp.storage.sqlite_store import SQLiteClusterStore
  8. def refresh_clusters(topic: str | None = None, limit: int = 80) -> None:
  9. store = SQLiteClusterStore(DB_PATH)
  10. articles = fetch_breakingthenews_articles(limit=limit)
  11. clustered_by_topic = dedup_and_cluster_articles(articles)
  12. for t, clusters in clustered_by_topic.items():
  13. if topic and t != topic:
  14. continue
  15. enriched = [enrich_cluster(c) for c in clusters]
  16. store.upsert_clusters(enriched, topic=t)