diff --git a/rss.py b/rss.py index cb76d7c..c889d98 100644 --- a/rss.py +++ b/rss.py @@ -2,33 +2,23 @@ import feedparser class FeedItem: - def __init__(self, url: str, title: str, description: str, date: str) -> None: - self.url = url - self.title = title - self.description = description - self.date = date + def __init__(self, item: feedparser.util.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, items: list[FeedItem]) -> None: + def __init__(self, url: str, feed: feedparser.util.FeedParserDict) -> None: self.url = url - self.items = items + self.items = self.__get_items(feed.entries) + + def __get_items(self, items: list[feedparser.util.FeedParserDict]) -> list[FeedItem]: + list_items = [] + for item in items: + list_items.append(FeedItem(item)) + return list_items class RssReader: def get_feed(self, url: str) -> Feed: - f = feedparser.parse(url) - items = self.__get_items(f.entries) - return Feed(url, items) - - def __convert_to_feed_item(self, item: feedparser.util.FeedParserDict) -> FeedItem: - title = item.get('title', '') - url = item.get('link', '') - description = item.get('summary', '') - date = item.get('published', '') - return FeedItem(url, title, description, date) - - def __get_items(self, items: list) -> list: - list_items = [] - for item in items: - list_items.append(self.__convert_to_feed_item(item)) - return list_items - + return Feed(url, feedparser.parse(url))