#!/usr/bin/env python3 import sys from functools import partial as p from ipo import ipo, write, starstarmap from page import blog_page_metadata BASE_URL = "https://www.braindeaddev.com/P5t7oFqPF7oEX" DOC_TEMPLATE = """ Midgard's blog {last_updated} Midgard {url}{0} """ ITEM_TEMPLATE = """ {title} {path} {published_rfc822} {url} {summary} """ # {category} def iso8601torfc822(iso8601): # pylint: disable=invalid-name y, m, d = map(int, iso8601.split("-")) month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][m] return f"{d} {month} {y} 00:00:00 UTC" def main(): items = ( ipo(sys.argv[1:]) | p(map, blog_page_metadata) | p(sorted, key=lambda x: x["published"]) | p(map, lambda x: { **x, "published_rfc822": iso8601torfc822(x["published"]), "url": f"{BASE_URL}/{x['path']}" }) | list ) last_date = items.data[-1]["published_rfc822"] ( items | p(starstarmap, ITEM_TEMPLATE.format) | "".join | p(DOC_TEMPLATE.format, url=BASE_URL, last_updated=last_date) | write ) if __name__ == '__main__': main()