From 629db4c25d456f9ba9a5a9370b11620eac585735 Mon Sep 17 00:00:00 2001 From: mitsuha_s Date: Sat, 11 Jun 2022 16:46:19 +0000 Subject: [PATCH] fix methods in rss.py --- rss.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/rss.py b/rss.py index 8389972..a6b243e 100644 --- a/rss.py +++ b/rss.py @@ -2,10 +2,11 @@ import feedparser class FeedItem(): - def __init__(self, url: str, title: str, description: str) -> None: + def __init__(self, url: str, title: str, description: str, date: str) -> None: self.url = url self.title = title self.description = description + self.date = date class Feed(): def __init__(self, url: str, items: list[FeedItem]) -> None: @@ -18,14 +19,12 @@ class RssReader(): items = self.__get_items(f.entries) return Feed(url, items) - def __convert_to_feed_item(self, item: dict) -> FeedItem: - if 'title' in item: - title = item['title'] - if 'link' in item: - url = item['link'] - if 'summary' in item: - description = item['summary'] - return FeedItem(url, title, description) + 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 = []