From 150223ae58692963dae801a2fb89cc76b56eac2e Mon Sep 17 00:00:00 2001 From: il Date: Fri, 4 Aug 2023 02:17:14 +0200 Subject: [PATCH] atom feed generator --- atom_gen.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 atom_gen.py diff --git a/atom_gen.py b/atom_gen.py new file mode 100755 index 00000000..2bbe3d7a --- /dev/null +++ b/atom_gen.py @@ -0,0 +1,45 @@ +#! /usr/bin/python3 + +# needs lowdown and feegden installed +# feedgen can be installed with pip +# also expects that *.md files are in blog/ directory + +from feedgen.feed import FeedGenerator +import subprocess +import os + +blogs_dir = os.fsencode("blog") + +def blogposts_list_gen(): + output_list = [] + for file in os.listdir(blogs_dir): + filename = os.fsdecode(file) + if filename.endswith(".md"): + full_path = "blog/" + filename + + author = subprocess.run("lowdown -X author " + full_path, capture_output=True, shell=True, text=True).stdout.strip() + title = subprocess.run("lowdown -X title " + full_path, capture_output=True, shell=True, text=True).stdout.strip() + time = subprocess.run("lowdown -X time " + full_path, capture_output=True, shell=True, text=True).stdout.strip() + content_html = subprocess.run("lowdown " + full_path, capture_output=True, shell=True, text=True).stdout.strip() + + output_list.append([author, title, time, content_html, full_path]) + return output_list + +def feedgen(blogs): + fg = FeedGenerator() + fg.id('http://dmz.rs/') + fg.title('Decentrala Blog') + fg.author( {'name':'Decentrala','email':'dmz@dmz.rs'} ) + fg.link( href='https://dmz.rs/atom.xml', rel='self' ) + + for post in blogs: + fe = fg.add_entry() + fe.id("https://dmz.rs/" + post[4][:-3] + ".html") + fe.author({'name': post[0]}) + fe.title(post[1]) + fe.updated(post[2]) + fe.content(content=post[3], type='html') + + fg.atom_file('atom.xml') + +feedgen(blogposts_list_gen())