#!/usr/bin/env python

if __name__ == '__main__':
    print 'Content-type: text/html; charset=utf-8\n'
    print """\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
      <title>Books I\'ve read</title>
      <link rel="stylesheet" type="text/css" href="http://dlade.net/yui/build/reset/reset-min.css">
      <link rel="stylesheet" type="text/css" href="style.css">
      <link rel="icon" href="/favicon.gif" type="image/x-icon">
      <link rel="shortcut icon" href="/favicon.gif" type="image/x-icon">
      <meta name="description" content="A list of books read by David Tolnem">
    </head>
    <body>
    <div id="body">
"""
    print '<div id="header"><h1>Books read by David Tolnem</h1></div>'
    print """<p>Below is a list of books that I've read. The list is very
incomplete before 2006, and only starts properly in 2007. I still have
everything that is not fiction or that I read after 2007, so if you see
anything you would like to borrow, just ask.</p>"""
    data = open('/var/www/books/books.txt').readlines()
    print '<div id="books">'
    print '<ul>'
    for entry in data:
        date, author, title = entry.decode('iso-8859-1').split('|', 2)
        out = '<li>%s - %s, %s</li>' % (date, author, title)
        print out.encode('utf-8', 'xmlcharrefreplace')
    print '</ul>'
    print '</div>'
    print '</div>'
    print '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">_uacct = "UA-1357868-1";urchinTracker();</script>'
    print '</body></html>'
