#!/bin/python
import os
import sys
from glob import glob
from datetime import datetime
with open('header.html') as f:
header = f.read().decode('utf-8')
with open('footer.html') as f:
footer = f.read().decode('utf-8')
mails = sorted(glob('*.raw'))
latest = None
def format_title(name):
return datetime.strptime(name, '%Y-%m-%d').strftime('%B') + ' Newsletter'
navigation = u'
'
navigation += u'- Pad.ma Newsletter
'
for mail in reversed(mails):
name = mail[:-4]
navigation += u'- %s
' % (name, format_title(name))
if not latest:
latest = "%s.html" % name
navigation += u'
'
for mail in reversed(mails):
name = mail[:-4]
print name
title = format_title(name)
nav = navigation.replace(u'%s' % (name, title), u'%s' % title)
with open(mail) as f:
body = f.read().decode('utf-8')
body = '' + body + '
'
with open('%s.html' % name, 'w') as f:
f.write(header.encode('utf-8'))
f.write(nav.encode('utf-8'))
f.write(body.encode('utf-8'))
f.write(footer.encode('utf-8'))
os.system('ln -sf "%s" index.html' % latest)