#!/usr/bin/env python3 from sys import argv, exit from os import walk, path from random import choice, seed from textwrap import indent import time, urllib.parse, re, subprocess from article_utils import parse_metadata from rfc822 import stringify_date import config if len(argv) <= 1: print("No directory was supplied") exit(-1) seed() # todo: Find the latest pubDate feed = f""" {config.title} {config.address} {config.description() if callable(config.description) else config.description} {config.language} {stringify_date(time.gmtime(int(time.time())))} """ body_taker = re.compile(r"(.*)", re.DOTALL) for root, dirs, _ in walk(argv[1]): for d in dirs: metadata = parse_metadata(path.abspath(root + '/' + d + "/page.mmd")) feed += ( " \n" f""" {metadata.get("Title", "No title!? ;-;")}\n""" ) body = subprocess.getoutput(f"./tools/mmd/build/multimarkdown {root}/{d}/page.mmd") feed += ( " \n" " \n" " \n" ) if "Date" in metadata: feed += \ f""" {stringify_date(metadata["Date"])}\n""" feed += ( f""" /articles/{d}\n""" f""" {config.address}/articles/{urllib.parse.quote(d)}\n""" " \n" ) break feed += """ """ print(feed)