From 58b762a53a5e64d6a6ea6999009d1899f7b6a4da Mon Sep 17 00:00:00 2001 From: Matthew Fennell Date: Sun, 23 Aug 2026 22:39:35 +0100 Subject: Add RSS feed plugins These are used to save each feed entry to a file. --- plaintext.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 plaintext.py (limited to 'plaintext.py') diff --git a/plaintext.py b/plaintext.py new file mode 100644 index 0000000..19b17cd --- /dev/null +++ b/plaintext.py @@ -0,0 +1,52 @@ +# SPDX-FileCopyrightText: 2026 Matthew Fennell +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from feed2exec.utils import slug + +import logging +import os +import uuid + +def output(*args, feed=None, item=None, session=None, **kwargs): + + logging.debug(f'args: {args}') + logging.debug(f'feed: {feed}') + logging.debug(f'item: {item}') + logging.debug(f'session: {session}') + + title = item.get('title', str(uuid.uuid4())) + + if not args or len(args) != 1: + logging.error(f'Expected args to be a path, but got {args}') + return False + + if not item.get('link'): + logging.error(f'Link not given') + return False + + if not item.get('content_plain'): + logging.error(f'content_plain not given') + return False + + if not feed.get('name'): + logging.error(f'Feed name not given') + return False + + feed_dir = args[0] + + if not os.path.exists(feed_dir): + logging.error(f'Path {feed_dir} does not exist') + + if feed.get('catchup'): + return True + + path = '-'.join([slug(feed.get('name')), slug(title)]) + path = os.path.join(feed_dir, path) + + with open(path, 'w') as content: + logging.info(f'Writing {item.title} to {path}') + content.write(item.get('content_plain')) + content.write(item.get('link') + os.linesep) + + return True -- cgit v1.2.3