genai-rss-space / rss_reader.py
8shanrahan's picture
Update rss_reader.py
b309d1d verified
raw
history blame contribute delete
688 Bytes
import feedparser
from newspaper import Article
def fetch_articles(rss_urls, limit=3):
articles = []
for url in rss_urls:
feed = feedparser.parse(url)
for entry in feed.entries[:1]: # limit to 1 or 2 max for entry in feed.entries[:limit]:
try:
article = Article(entry.link)
article.download()
article.parse()
articles.append({
"title": entry.title,
"link": entry.link,
"text": article.text,
"published": entry.published
})
except:
continue
return articles