newsletter/update.py

47 lines
1.2 KiB
Python
Raw Normal View History

2010-03-31 14:28:39 +00:00
#!/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'<ul id="nav">'
navigation += u'<li><span class="title">Pad.ma Newsletter</span></li>'
for mail in reversed(mails):
name = mail[:-4]
navigation += u'<li><a href="%s.html">%s</a></li>' % (name, format_title(name))
if not latest:
latest = "%s.html" % name
navigation += u'</ul>'
for mail in reversed(mails):
name = mail[:-4]
print name
title = format_title(name)
nav = navigation.replace(u'<li><a href="%s.html">%s</a></li>' % (name, title), u'<li>%s</li>' % title)
with open(mail) as f:
body = f.read().decode('utf-8')
body = '<div id="content">' + body + '</div>'
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)