#!/usr/bin/env python
'Atom Script, by Sean B. Palmer'
import os, re, time
domain = os.environ.get('SERVER_NAME')
script = os.environ.get('SCRIPT_NAME')
r_title = re.compile('(?s)
(.*?), by (.*?) ')
r_entry = re.compile('(?s)(.*?)
')
if script:
index = open('index.html').read()
title, author = r_title.search(index).groups()
label = script.lstrip('/').rsplit('/', 1)[0]
entries = []
for (date, content) in r_entry.findall(index):
try: t = time.strptime(date, '%d %B %Y, %H:%M')
except ValueError: continue
updated = time.strftime('%Y-%m-%dT%H:%M:%SZ', t)
content = content.replace(']]>', ']]>]]>'
print ' %s ' % title
print ' ' % (domain, label)
print ' tag:%s,2006:%s ' % (domain, label)
if entries:
print ' %s ' % entries[0][1]
for (date, updated, content) in entries:
print ' ' % (domain, label)
print ' tag:%s,2006:%s:%s ' % (domain, label, updated)
print ' %s ' % date
print ' %s ' % updated
print ' %s ' % author
print ' ' % content
print ' '
print ''