tg_rss_bot/rss.py
mitsuha_s b2c49a583a
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
refactor rss.py
2022-06-12 13:18:55 +00:00

25 lines
776 B
Python

import feedparser
class FeedItem:
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, feed: feedparser.util.FeedParserDict) -> None:
self.url = url
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:
return Feed(url, feedparser.parse(url))