User:Lidia.Pereira/PNMIII/CEIII

From XPUB & Lens-Based wiki

Continuation of this , now handling conflict. http://headroom.pzwart.wdka.hro.nl/~lpereira/cgi-bin/exquisfrontpage.cgi


#!/usr/bin/env python
#-*- coding:utf-8 -*-
import cgi, urllib
import cgitb; cgitb.enable()
import urlparse

form = cgi.FieldStorage()
form_text_content = form.getvalue('textcontent')
form_last_word = form.getvalue('lastword')

database = open("database.txt")
lines = database.readlines()

def last_Word():
    for line in lines:
        a = line.split()
        for word in a:
            lastword = word
    return lastword
writePar = False
lastWord = last_Word()
x = 0
story = " "
if lastWord == form_last_word and form_text_content != None:
    story = last_Word()
    database = open("database.txt","a")
    database.write(form_text_content + "\n")
    database = open("database.txt")
    lines = database.readlines() 
    lastWord = last_Word()
elif lastWord != form_last_word and form_text_content != None:
    writePar = True
print "Content-Type: text/html"
print 
print """
    <!DOCTYPE html>
    <html>
    <head>
    <link href='http://fonts.googleapis.com/css?family=Share+Tech+Mono' rel='stylesheet' type='text/css'>
    <link rel='stylesheet' type='text/css' href='/cadavreexquiscss.css'>
    <title>Cadavre Exquis</title>
    </head>
    <body>"""

print """ <a href='exquisfrontpage.cgi'><img src='/cadavrebanner.png' class = 'banner2'/></a> <br>
    <a href='cadavrexquisresults.cgi'><img src='/nonsenselink.png' class='nonsenselink'></a>
    <p class='exquisrule'> The only rule is that you have to start your contribution\
 with the word you see on the form! </p> """
if writePar:
    print """<p class = 'exquisrule'> There seems to be a conflict, try again please! </p>"""
print """<form method='post'>
    <input type='text' name ='textcontent' id='reply' size='121' class ='exquis' placeholder='"""+lastWord+"""' />
    <input type='hidden' name ='lastword' value = '"""+ lastWord +"""' /> """
print """<input type='submit' value='Contribute!' class ='button' /> """