From 56a863f9f11340a9310907e4131b9dc7483df623 Mon Sep 17 00:00:00 2001 From: Cullum Smith Date: Wed, 3 Jul 2024 12:25:01 -0400 Subject: initial commit --- scripts/bloglist.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 scripts/bloglist.py (limited to 'scripts/bloglist.py') diff --git a/scripts/bloglist.py b/scripts/bloglist.py new file mode 100755 index 0000000..9e10354 --- /dev/null +++ b/scripts/bloglist.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import argparse +from common import get_blog_posts + +DATE_FORMAT = '%Y-%m-%d' + +parser = argparse.ArgumentParser('bloglist') +parser.add_argument('BLOG_DIR', type=str, help='Directory containing markdown blog posts') +parser.add_argument('LIMIT', nargs='?', default=None, type=int, help='Maximum number of posts to show') +args = parser.parse_args() + +posts = get_blog_posts(args.BLOG_DIR) + +if args.LIMIT is not None: + posts = posts[0:args.LIMIT] + +if len(posts) == 0: + print('Nothing has been posted yet!') +else: + for post in posts: + post_date = post['date'].strftime(DATE_FORMAT) + + print(f'- [{post["title"]}]({post["href"]}) ({post_date})\n') + if post['description']: + print(f' {post["description"]}\n') -- cgit v1.2.3