#!/usr/bin/python

import sys
sys.path.append('/home/acb/null_include')

from nullcgi import *

import time
import dircache
import re

# print a line describing a book we've read

def printline(fname):
  #print fname
  headers = {}
  review = ''
  fd = open(fname)
  str = fd.readline()[:-1]
  while(len(str)>0):
    (key, value) = (re.split(': +', str, 1)+[''])[:2]
    headers[key] = value
    # print "[%s] = [%s]"%(key,value)
    str = fd.readline()[:-1]
  str = fd.readline()
  while str:
    review = review + str
    str = fd.readline()

  print "<LI><DT>%(Author)s, <I>%(Title)s</I>"%headers
  if review:
    print "<DD>%s"%review
  print "<P>"


(cyear,cmonth,cday) = time.localtime(time.time())[0:3]

print "Content-Type: text/html\n"

print readfile('TOP')

#year = cyear	# the year we're looking at
for year in range(cyear, 1999, -1):
 if year == cyear:
   sm = cmonth
 else:  sm = 12
 for month in range(sm,0,-1):
  dirname = "%04d/%02d"%(year,month)
  filenames = dircache.listdir(dirname)
  filenames.sort()
  filenames.reverse()

  if filenames != []:
    print "<H3>%s</H3>"%time.strftime("%B %Y",(year,month,1,0,0,0,0,0,0))

    print "<UL>"
    for fn in filenames:
      if fn[-2:] == '.r':
        printline("%s/%s"%(dirname,fn))
      # print "<LI>%s"%fn

    print "</UL>"

print readfile('BOTTOM')
