tg_rss_bot/rss.py
Alexey Skobkin 6ac2610637
All checks were successful
continuous-integration/drone/push Build is passing
Logging added (#34)
Reviewed-on: #34
Reviewed-by: Miroslavsckaya <miroslavsckaya@noreply.git.skobk.in>
Co-authored-by: Alexey Skobkin <skobkin-ru@ya.ru>
Co-committed-by: Alexey Skobkin <skobkin-ru@ya.ru>
2022-07-10 15:07:26 +03:00

35 lines
943 B
Python

from logging import Logger
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 __init__(self, logger: Logger):
self.log: Logger = logger
self.log.debug('RssReader.__init__(logger=%s)', logger)
def get_feed(self, url: str) -> Feed:
self.log.debug('get_feed(url=\'%s\')', url)
return Feed(url, parse(url))