#!/usr/bin/env python # coding=utf-8 """ contents.py - Juno Contents Module Copyright 2008, Sean B. Palmer, inamidst.com Licensed under the Eiffel Forum License 2. http://inamidst.com/whits/code/juno/ """ import cgitb cgitb.enable() import os, time, glob year = os.environ.get('REQUEST_URI').rstrip('/').split('/').pop() def title(filename): f = open(filename) f.next() title_line = f.next() title = title_line.rstrip('\r\n')[7:-8] f.close() return title def entries(): # yield URI, updated, title, content potential = [] for fn in glob.glob('*.html') + glob.glob('**/*.html'): mtime = os.path.getmtime(fn) path = fn[:-5].lstrip('./') if (len(path) > 2) and (path[-3] == '/'): updated = year + '-' + path.replace('/', '-') + 'T23:59:59Z' else: updated = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(mtime)) potential.append((updated, fn, path)) for updated, fn, path in sorted(potential, reverse=True): f = open(fn) first = f.next() if first.startswith(''): yield path, updated, title(fn) else: f.close() def main(options): print "Content-Type: text/html; charset=utf-8" print def opt(key, alternative, options=options, year=year): return options.get(key, alternative).replace('$year', year) articles = [] for root, dirs, files in os.walk('.'): for name in files: if not name.endswith('.html'): continue fn = os.path.join(root, name) articles.append((os.path.getmtime(fn), fn[:-5], title(fn))) print """\