Spaces:
Sleeping
Sleeping
| 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 | |