From 3d0b03a8adf4b46909488396066e5dfbfc20677b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 17 Oct 2019 13:49:09 +0200 Subject: [PATCH] A WIP RSS monitor --- royalnet/monitors/rss.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 royalnet/monitors/rss.py diff --git a/royalnet/monitors/rss.py b/royalnet/monitors/rss.py new file mode 100644 index 00000000..a97c45b4 --- /dev/null +++ b/royalnet/monitors/rss.py @@ -0,0 +1,42 @@ +import typing +import feedparser +import asyncio +import datetime +from .monitor import Monitor +from ..utils import asyncify + + +class RssMonitor(Monitor): + def __init__(self, url: str, interval: float, *, loop: asyncio.AbstractEventLoop): + super().__init__(interval, loop=loop) + self.url: str = url + self._last_feed: feedparser.FeedParserDict = None + + @property + def feed_title(self) -> typing.Optional[str]: + if self._last_feed is None: + return None + return self._last_feed.feed.title + + @property + def feed_link(self) -> typing.Optional[str]: + if self._last_feed is None: + return None + return self._last_feed.feed.link + + @property + def feed_description(self) -> typing.Optional[str]: + if self._last_feed is None: + return None + return self._last_feed.feed.description + + @property + def feed_published(self) -> typing.Optional[datetime.datetime]: + if self._last_feed is None: + return None + return self._last_feed.feed.published_parsed + + async def check(self): + self._last_feed = await asyncify(feedparser.parse, self.url) + # TODO + ...