diff options
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 |
