|
@@ -5,7 +5,7 @@ from typing import Any, Dict, List
|
|
|
|
|
|
|
|
import feedparser
|
|
import feedparser
|
|
|
|
|
|
|
|
-from news_mcp.config import RSS_FEED_URL
|
|
|
|
|
|
|
+from news_mcp.config import RSS_FEED_URL, RSS_FEED_URLS
|
|
|
|
|
|
|
|
|
|
|
|
|
def _canonical_url(url: str) -> str:
|
|
def _canonical_url(url: str) -> str:
|
|
@@ -14,28 +14,39 @@ def _canonical_url(url: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_breakingthenews_articles(limit: int = 50) -> List[Dict[str, Any]]:
|
|
def fetch_breakingthenews_articles(limit: int = 50) -> List[Dict[str, Any]]:
|
|
|
- feed = feedparser.parse(RSS_FEED_URL)
|
|
|
|
|
|
|
+ rss_urls = [u.strip() for u in RSS_FEED_URLS.split(",") if u.strip()]
|
|
|
|
|
+ if not rss_urls:
|
|
|
|
|
+ rss_urls = [RSS_FEED_URL]
|
|
|
|
|
+
|
|
|
articles: List[Dict[str, Any]] = []
|
|
articles: List[Dict[str, Any]] = []
|
|
|
|
|
|
|
|
- for entry in feed.entries[:limit]:
|
|
|
|
|
- title = str(getattr(entry, "title", "")).strip()
|
|
|
|
|
- url = _canonical_url(str(getattr(entry, "link", "")).strip())
|
|
|
|
|
- source = "BreakingTheNews"
|
|
|
|
|
- timestamp = str(getattr(entry, "published", "")) or str(getattr(entry, "updated", ""))
|
|
|
|
|
- summary = str(getattr(entry, "summary", "")) or str(getattr(entry, "description", ""))
|
|
|
|
|
-
|
|
|
|
|
- if not title or not url:
|
|
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- articles.append(
|
|
|
|
|
- {
|
|
|
|
|
- "title": title,
|
|
|
|
|
- "url": url,
|
|
|
|
|
- "source": source,
|
|
|
|
|
- "timestamp": timestamp,
|
|
|
|
|
- "summary": summary,
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ # Evenly pull from feeds; keep total below `limit`.
|
|
|
|
|
+ per_feed_limit = max(1, int(limit / max(1, len(rss_urls))))
|
|
|
|
|
+
|
|
|
|
|
+ for feed_url in rss_urls:
|
|
|
|
|
+ feed = feedparser.parse(feed_url)
|
|
|
|
|
+ for entry in feed.entries[:per_feed_limit]:
|
|
|
|
|
+ title = str(getattr(entry, "title", "")).strip()
|
|
|
|
|
+ url = _canonical_url(str(getattr(entry, "link", "")).strip())
|
|
|
|
|
+ source = "RSS"
|
|
|
|
|
+ timestamp = str(getattr(entry, "published", "")) or str(getattr(entry, "updated", ""))
|
|
|
|
|
+ summary = str(getattr(entry, "summary", "")) or str(getattr(entry, "description", ""))
|
|
|
|
|
+
|
|
|
|
|
+ if not title or not url:
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ articles.append(
|
|
|
|
|
+ {
|
|
|
|
|
+ "title": title,
|
|
|
|
|
+ "url": url,
|
|
|
|
|
+ "source": source,
|
|
|
|
|
+ "timestamp": timestamp,
|
|
|
|
|
+ "summary": summary,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if len(articles) >= limit:
|
|
|
|
|
+ return articles
|
|
|
|
|
|
|
|
return articles
|
|
return articles
|
|
|
|
|
|