#! /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())