User:Lidia.Pereira/PNMIII/CEIII

From XPUB & Lens-Based wiki
< User:Lidia.Pereira‎ | PNMIII
Revision as of 11:16, 9 April 2014 by Lidia.Pereira (talk | contribs) (Created page with "Continuation of this , now handling conflict. <syntax highlight ="python"> #!/usr/bin/env python #-*- coding:utf-8 -*- import cgi, urllib...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Continuation of this , now handling conflict.

<syntax highlight ="python">

  1. !/usr/bin/env python
  2. -*- 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'></a>

   <a href='cadavrexquisresults.cgi'></a>

The only rule is that you have to start your contribution with the word you see on the form!

"""

if writePar:

print """

There seems to be a conflict, try again please!

"""

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' /> """ </syntaxhighlight>