diff options
| author | Matthew Fennell <matthew@fennell.dev> | 2026-08-23 22:39:35 +0100 |
|---|---|---|
| committer | Matthew Fennell <matthew@fennell.dev> | 2026-08-23 22:39:35 +0100 |
| commit | 58b762a53a5e64d6a6ea6999009d1899f7b6a4da (patch) | |
| tree | 950612344353c79d069b2f2185c8613c14ce7179 /plaintext.py | |
| parent | 77078787b2568d791a0f180737d14070be46f23c (diff) | |
Add RSS feed plugins
These are used to save each feed entry to a file.
Diffstat (limited to 'plaintext.py')
| -rw-r--r-- | plaintext.py | 52 |
1 files changed, 52 insertions, 0 deletions
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 <matthew@fennell.dev> +# +# 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 |
