#!/usr/bin/python
import datetime
import parsepalmdatebook
import cgi
import xml.sax.saxutils
dateBookName = 'datebook.txt'
def getXMLDateString(date):
return "%d%d%d" % (date.year, date.month, date.day)
def getXMLTimeString(time):
return "%d%d%d" % (time.hour, time.minute, time.second)
form = cgi.FieldStorage()
month = int(form.getfirst('month'))
year = int(form.getfirst('year'))
day = int(form.getfirst('day'))
#month = 12
#year = 2005
#day = 20
numDays = form.getfirst('numDays')
if (numDays == None):
numDays = 28
else:
try:
numDays = int(numDays)
except:
numDays = 28
entries = parsepalmdatebook.getEntries(dateBookName, datetime.date(year, month, day), numDays)
print "Content-type: text/xml\n\n"
print ""
entryKeys = entries.keys()
entryKeys.sort()
for date in entryKeys:
for entry in entries[date]:
print ""
print "%s" % (getXMLDateString(date))
print "%s" % (getXMLDateString(entry.getStartDate()))
if (entry.getEndDate()):
print "%s" % (getXMLDateString(entry.getEndDate()))
if (isinstance(entry.startDate, datetime.datetime)):
print "%s" % (getXMLTimeString(entry.startDate.time()))
if (entry.getEndDate()):
print "%s" % (getXMLTimeString(entry.endDate.time()))
print "%s" % (xml.sax.saxutils.escape(entry.title))
if (entry.category):
print "%s" % (xml.sax.saxutils.escape(entry.category))
# TODO - repeats?
print "\n"
print ""
print "\n"