User:Lidia.Pereira/PNMII/WB/CE
This is a simple prototype of a cgi-based Cadavre Exquis which I hope to use in the future, applied to my Self-Directed Research. It also still lacks a way to handle multiple users editing the same part of the narrative.
<syntaxhighlight lang="python">
- !/usr/bin/env python
- -*- coding:utf-8 -*-
import cgi, urllib import cgitb; cgitb.enable()
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>
Welcome! Whether you want to participate in the Cadavre Exquis\ or just read the Tales of Nonsense, you've come to the right place. Plase, proceed!
<a href = 'cadavrexquisresults.cgi'> </a> <a href = 'cadavrexquis.cgi'> </a>
</body> </html>
"""
database = open("database.txt", "a") database = open("database.txt") lines = database.readlines()
if not lines:
database = open("database.txt","a") database.write("Begin!"+"\n")
</syntax>
<syntaxhighlight lang="python">
- !/usr/bin/env python
- -*- coding:utf-8 -*-
import cgi, urllib import cgitb; cgitb.enable() import urlparse
form = cgi.FieldStorage() text_content = str(form.getvalue('textcontent'))
database = open("database.txt","a") if text_content != "None":
database.write(text_content + "\n")
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
lastWord = last_Word() x = 0
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> <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!
<form method='post'> <input type='text' name ='textcontent' id='reply' size='121' class ='exquis' placeholder='"""+lastWord+"""'/> <input type='submit' value='Contribute!' class ='button'/> </form> </body> </html> """
</syntax>
<syntaxhighlight lang="python">
- !/usr/bin/env python
- -*- coding:utf-8 -*-
import cgi, urllib import cgitb; cgitb.enable() import time
print "Content-Type: text/html"
print
print """
<!DOCTYPE html> <html> <head> <meta charset = utf-8 > <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'> <style> body { background-color: #FFF; } </style> <title>Tales of Nonsense</title> </head> <body> <a href='exquisfrontpage.cgi'></a>
<a href='cadavrexquis.cgi'></a>
x = 0 database = open("database.txt") lines = database.readlines() numberlines = len(lines)
def getBlob():
blob = "" for line in lines[1:numberlines]: data = line.strip("\n") blob = blob + data + " " return blob
blob = getBlob() blobies = blob.split(".") lenbloblies = len(blobies) n = 0 for x in range (lenbloblies-3):
paragraph = " " for blobi in blobies[n:n+3]: paragraph = paragraph + blobi + "." n = n + 3print """
"""+paragraph+"""
""" print """</body> </html>"""
</syntax>