#!/usr/bin/python # Import the CGI module import cgi # Required header that tells the browser how to render the HTML. print "Content-Type: text/html\n\n" def generateheader(message, iserror): print "\n" print "\n" print "\tFinal Presentation Cancellation\n" print "\n" print "\n" print "\t

", if iserror == True: print "", print message if iserror == True: print "", print "

\n" print "\t\n" print "\t\t\n" # Define function to generate HTML form. def generate_form(emailval = None): infile = open("times.txt") onetocancel = False for line in infile: values = line.split("%") print "\t\t" if(len(values) >= 3): print "\t\t\t", print "" print "" onetocancel = True print "" infile.close() if onetocancel == False: print "" print "\t
Date: ", values[0], "Time: ", values[1], "Name: ", values[2], "
You are not signed up for a presentation. Sign up here!
\n" print "\t\n" print "\n" print "\n" return print "" if emailval != None: print "" print "" else: print "
Email:
" print "
Email:
" print "" print "" print "\t\n" print "\t\n" print "\n" print "\n" def cancel(email, time): timelist = time.split("%") infile = open("times.txt") outfile = open("tmptimes.txt", "w") found = False for line in infile: values = line.split("%") if values[0].strip() == timelist[0].strip() and values[1].strip() == timelist[1].strip() and len(values) > 3 and values[3].strip() == email.strip(): found = True line = values[0].strip() + "%" + values[1].strip() + "\n" outfile.write(line) infile.close() outfile.close() infile = open("tmptimes.txt") outfile = open("times.txt", "w") for line in infile: outfile.write(line) infile.close() outfile.close() return found # Define main function. def main(): form = cgi.FieldStorage() if (form.has_key("email") and form.has_key("time")): cancelled = cancel(form["email"].value, form["time"].value) if cancelled == True: generateheader("Please reschedule here.", False) generate_form() else: generateheader("There was an error with your cancellation. Try again.", True) generate_form() elif form.has_key("email") or form.has_key("time"): generateheader("There was an error with your cancellation. Try again.", True) generate_form() else: generateheader("Please select time and enter your email address.", False) generate_form() main()