#! /usr/bin/python import cgitb; cgitb.enable() import cgi import glob import os import sys import markdown BASE = '/var/lib/wishlists' f = cgi.FieldStorage() title = 'Wishlists' content = [] u = f.getfirst('u') p = f.getfirst('p') if u: if p: if p.lower() not in ('dingo', 'jada'): content.append("

I'm sorry but that is not the right answer.

") else: txt = f.getfirst('txt') open(os.path.join(BASE, u), 'w').write(txt) content.append('

Okay, thanks!

') content.append('

Back to wishlists

') else: title = "%s's Wishlist" % cgi.escape(u) txt = open(os.path.join(BASE, u)).read() content.append('
') content.append('' % u) content.append('' % cgi.escape(txt)) content.append('
') content.append('What is the name of Amy and Neale\'s dog?') content.append('') content.append('') content.append('
') else: for fn in sorted(glob.glob(os.path.join(BASE, '*'))): u = os.path.basename(fn) content.append("

%s

" % cgi.escape(u)) content.append(markdown.markdown(open(fn).read())) content.append('

edit

' % u) print 'Content-type: text/html' print sys.stdout.flush() p = os.popen('m4 -DTITLE="%s" template.html.m4 -' % title, 'w') p.write('\n'.join(content)) p.close()