diff --git a/lib/urlwatch/reporters.py b/lib/urlwatch/reporters.py index 73576c96..e8e177d5 100644 --- a/lib/urlwatch/reporters.py +++ b/lib/urlwatch/reporters.py @@ -46,6 +46,9 @@ from .util import TrackSubClasses, chunkstring from .xmpp import XMPP +from feedgen.feed import FeedGenerator +import hashlib + try: import chump except ImportError: @@ -383,6 +386,37 @@ def submit(self): print(line) +class RssReporter(TextReporter): + """Print summary on stdout (the console) as RSS""" + + __kind__ = 'rss' + + def submit(self): + + body = '\n'.join(super().submit()) + if not body: + return + + # Text output within preformatted tag. + body = '
' + body + '
' + + # Create feed. + fg = FeedGenerator() + fg.title(self.config['feed']['title']) + fg.link( href=self.config['feed']['url'], rel='alternate' ) + fg.subtitle(self.config['feed']['subtitle']) + + # Create feed item + fe = fg.add_entry() + fe.title('New changes') + fe.content(body, type='CDATA') + id = hashlib.sha1(body.encode('utf-8')).hexdigest() + fe.id(id) + + # Output feed to STDOUT. + rss = fg.rss_str(pretty=True).decode("utf-8") + print(rss) + class EMailReporter(TextReporter): """Send summary via e-mail / SMTP""" diff --git a/lib/urlwatch/storage.py b/lib/urlwatch/storage.py index 661f9d99..0c06d944 100644 --- a/lib/urlwatch/storage.py +++ b/lib/urlwatch/storage.py @@ -92,6 +92,15 @@ 'color': True, }, + 'rss': { + 'enabled': False, + 'feed': { + 'title': 'urlwatch', + 'subtitle': 'Changes in my monitored URLs.', + 'url': 'http://example.com', + }, + }, + 'email': { 'enabled': False, diff --git a/requirements.txt b/requirements.txt index d61c89b2..ac27a93c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ keyring appdirs lxml cssselect +feedgen