#!/usr/bin/python
import cgi, os, os.path, time, re, xml.sax.saxutils
lockFileName = "files/todolock"
fileName = "files/todos.xml"
while(os.path.exists(lockFileName)):
time.sleep(.25)
lockFileHandle = open(lockFileName, "w")
lockFileHandle.write("locked")
lockFileHandle.close()
form = cgi.FieldStorage()
title = form.getfirst("title")
month = int(form.getfirst('month'))
year = int(form.getfirst('year'))
day = int(form.getfirst('day'))
if (form.has_key(note)):
note = form.getfirst('note')
oldFile = open(fileName, 'r')
oldFileLines = oldFile.readlines()
oldFile.close()
ticklerStartre = re.compile(r'')
ticklerEndre = re.compile(r'')
ticklerLineToInsert = '\n' % (month, year, day, xml.sax.saxutils.quoteattr(title))
oldFileLines.insert(len(oldFileLines) - 2, ticklerLineToInsert)
newFile = open(fileName, 'w')
for line in oldFileLines:
newFile.write(line)
newFile.close()
os.remove(lockFileName)
print "Content-type: text/plain\n\n"
print "done."