From 9f1b37fa346a7dcf77c1b6963a6d2e4b871fe5ed Mon Sep 17 00:00:00 2001 From: Stonewall Jackson Date: Sun, 22 Jan 2023 09:56:17 -0500 Subject: initial commit --- scripts/rss.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 scripts/rss.py (limited to 'scripts/rss.py') diff --git a/scripts/rss.py b/scripts/rss.py new file mode 100755 index 0000000..cf0cb9a --- /dev/null +++ b/scripts/rss.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import argparse +import email.utils +from datetime import datetime +from common import get_blog_posts + +parser = argparse.ArgumentParser('rss') +parser.add_argument('BLOG_DIR', type=str, help='Directory containing markdown blog posts') +parser.add_argument('--limit', default=15, type=int, help='Maximum number of posts to show') +parser.add_argument('--title', help='Feed title', required=True) +parser.add_argument('--description', help='Feed description', required=True) +parser.add_argument('--url', help='Root URL', required=True) +parser.add_argument('--blog-path', help='Blog path', required=True) +parser.add_argument('--feed-path', help='RSS feed path', required=True) +args = parser.parse_args() + +posts = get_blog_posts(args.BLOG_DIR) +posts = posts[0:args.limit] + +build_date = email.utils.format_datetime(datetime.now().astimezone()) + +print(f''' + + + {args.title} + {args.url}{args.blog_path} + en-US + {args.description} + {build_date} + ''') + +for post in posts: + pub_date = email.utils.format_datetime(post['date'].astimezone()) + + print(f''' + {post["title"]} + {args.url}{post["href"]} + {args.url}{post["href"]} + {pub_date}''') + + if 'description' in post: + print(f' {post["description"]}') + + print(' ') + +print('') +print('') -- cgit