47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
|
#!/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)
|
||
|
|