2022-05-29 20:17:03 +00:00
|
|
|
import feedparser
|
|
|
|
|
|
|
|
|
2022-06-11 22:51:39 +00:00
|
|
|
class FeedItem:
|
2022-06-12 13:18:55 +00:00
|
|
|
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', '')
|
2022-05-29 20:17:03 +00:00
|
|
|
|
2022-06-11 22:51:39 +00:00
|
|
|
class Feed:
|
2022-06-12 13:18:55 +00:00
|
|
|
def __init__(self, url: str, feed: feedparser.util.FeedParserDict) -> None:
|
2022-05-29 20:18:12 +00:00
|
|
|
self.url = url
|
2022-06-12 13:18:55 +00:00
|
|
|
self.items = self.__get_items(feed.entries)
|
2022-05-29 20:17:03 +00:00
|
|
|
|
2022-06-12 13:18:55 +00:00
|
|
|
def __get_items(self, items: list[feedparser.util.FeedParserDict]) -> list[FeedItem]:
|
2022-05-29 20:28:48 +00:00
|
|
|
list_items = []
|
|
|
|
for item in items:
|
2022-06-12 13:18:55 +00:00
|
|
|
list_items.append(FeedItem(item))
|
2022-05-29 20:28:48 +00:00
|
|
|
return list_items
|
2022-05-29 20:17:03 +00:00
|
|
|
|
2022-06-12 13:18:55 +00:00
|
|
|
class RssReader:
|
|
|
|
def get_feed(self, url: str) -> Feed:
|
|
|
|
return Feed(url, feedparser.parse(url))
|