#!/usr/bin/env python
"""
homepage - Make the Whits Homepage
Author: Sean B. Palmer, inamidst.com
"""

import sys, os
os.chdir(sys.argv[1])
sys.path = ['.'] + sys.path
from code.astraea.notes import notes

def main(): 
   o = open('feed.atom', 'wb')
   print >> o, '<feed xmlns="http://www.w3.org/2005/Atom">'
   print >> o, '<title>Gallimaufry of Whits</title>'
   print >> o, '<subtitle>When found, make a note of!</subtitle>'
   print >> o, '<link href="http://inamidst.com/whits/" />'
   print >> o, '<link rel="self" href="http://inamidst.com/whits/feed" />'
   print >> o, '<id>tag:inamidst.com,2006:whits</id>'

   for i, note in enumerate(notes()): 
      if i == 0: print >> o, '<updated>' + note.updated + '</updated>'
      print >> o, '<entry xml:base="http://inamidst.com/whits/">'
      print >> o, '<id>tag:inamidst.com,2006:whits:' + note.updated + '</id>'
      print >> o, '<link rel="alternate" type="text/html" '
      print >> o, '   href="http://inamidst.com/whits/' + note.path + '" />'
      print >> o, '<title>' + note.cite + '</title>'
      print >> o, '<updated>' + note.updated + '</updated>'
      print >> o, '<author><name>Sean B. Palmer</name></author>'
      print >> o, '<content type="html" '
      print >> o, ' xml:base="http://inamidst.com/whits/' + note.path + '">'
      print >> o, '<![CDATA[' + note.content + ']]>'
      print >> o, '</content>'
      print >> o, '</entry>'
   print >> o, '</feed>'
   o.close()

if __name__ == '__main__': 
   main()
