Miroslavsckaya
78467bc5fb
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #23 Reviewed-by: Alexey Skobkin <skobkin-ru@ya.ru>
27 lines
725 B
Python
27 lines
725 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', '')
|
|
if 'published' in item:
|
|
self.date = item.published_parsed()
|
|
else:
|
|
self.date = None
|
|
|
|
|
|
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))
|