tg_rss_bot/rss.py
2022-06-12 20:48:05 +00:00

22 lines
646 B
Python

from feedparser import FeedParserDict, parse
class FeedItem:
def __init__(self, item: FeedParserDict) -> None:
self.url = item.get('link', '')
self.title = item.get('title', '')
self.description = item.get('summary', '')
self.date = item.get('published', '')
class Feed:
def __init__(self, url: str, feed: FeedParserDict) -> None:
self.url = url
self.items = []
self.title = feed.feed.get('title', '')
for item in feed.entries:
self.items.append(FeedItem(item))
class RssReader:
def get_feed(self, url: str) -> Feed:
return Feed(url, parse(url))