#!/usr/bin/env python3
# Gallimaufry of Whits homepage

from html.parser import HTMLParser
from itertools import islice
from re import compile
from time import gmtime, strftime

unescape = HTMLParser().unescape
item = compile('''(?msx)
   ([0-9]{4}/[^<]+)</id> .*?
   <title>(.*?)</title> .*?
   <content[^>]+>(.*?)</content>
''')
year = strftime('%Y', gmtime())

print('<!doctype html>')
print('<meta charset="utf-8">')
print('<title>Gallimaufry of Whits: a weblog by Sean B. Palmer</title>')
print('<link rel="alternate" type="application/atom+xml" href="feed">')
print('<link rel="stylesheet" href="%s/style.css">' % year)
print('')
print('<p class="about"><a href="subscribe">Subscribe</a>')
print('&middot; <a href="%s/">Archives</a>' % year)
print('')
print('<h1>Gallimaufry of Whits</h1>')
print('')

with open("feed.atom") as f:
    text = f.read()
for (path, title, content) in item.findall(text):
    print('<h2><a href="%s">%s</a></h2>' % (path, title))
    print(unescape(content))
    print('')
