#!/usr/bin/env python3 from cgi import escape from glob import glob from itertools import islice from os.path import join from re import search from time import gmtime, strftime def metadata(year=strftime('%Y', gmtime())): for meta in glob(join(year, '.published', '*.html')): with open(meta) as f: yield int(f.read()), meta.replace('/.published', '') if __name__ == '__main__': print('') print(' Gallimaufry of Whits') print(' ') print(' ') print(' tag:sbp.so,2011:inamidst.com/whits') print(' Sean B. Palmer') print(' %s' % strftime('%Y-%m-%dT%H:%M:%SZ', gmtime())) for published, name in islice(sorted(metadata(), reverse=True), 5): with open(name) as f: text = f.read() path = join('whits', name.rsplit('.', 1)[0]) title = search('(.*)', text).group(1) content = text.split('', 1).pop().lstrip() updated = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime(published)) print(' ' % path) print(' tag:sbp.so,2011:%s' % path) print(' %s' % title) print(' %s' % updated) print(' ' % path) print(' %s' % escape(content)) print(' ') print ('')