User:Eleanorg/2.2/yes

From XPUB & Lens-Based wiki

The word yes is printed to screen. User votes 'yes', 'no', or 'maybe'. For each 'maybe' the word gets x amount bigger. For each 'yes' it gets twice that amount bigger. Each no is counted as zero and does not affect the size.

Code

Make db

Make a db to count the votes. Run once.

#!/usr/bin/python
#-*- coding:utf-8 -*-

import pymongo
from pymongo import Connection
 
connection = Connection()
myDB = connection['yes1']
collection = myDB.collection 

# create db entry to track votes, starting at zero.
entry = {'title': 'yesVotes', 'tally': 0 }
collection.insert(entry)

Voting interface

Display the word 'YES', with css properties determined by tally in db.

#!/usr/bin/python
#-*- coding:utf-8 -*-
 
 
import cgi
import cgitb; cgitb.enable()
import pymongo
from pymongo import Connection
import random
 
#========= get votes tally from db

connection = Connection()
myDB = connection['yes1']
collection = myDB.collection 

entry = myDB.collection.find({'title': 'yesVotes'})
tally = entry[0]['tally']				# entry[0] is the hash in our db. Grab value of 'tally' from the hash.

cssOpacity = float(tally) * 0.001
cssFontsize = float(tally) * 0.0001


#========= display the word styled according to no. of votes

 
print "Content-Type: text/html"
print 
print """
<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <style type="text/css">
    	.input {margin:auto; text-align:center; padding:1%; border-bottom:1px solid #ddd;}
    	input span{float:left;margin:5%;}
    	.yesDiv {min-width:80%;margin:auto;padding:5%; text-align:center}
    	.yes {font-size:""" + str(cssFontsize) + """; opacity:""" + str(cssOpacity) + """;}
    	
    </style>
 
  </head>
 
<body>
<div class="input">
	        <form action="3updateTally.cgi" name="inputForm">	
		<span><input type="radio" name="vote" value="2">Yes</span>
		<span><input type="radio" name="vote" value="0">No</span>
		<span><input type="radio" name="vote" value="1">Maybe</span><br /><br />
	
		<input type="submit" value="Submit" />
		</form>
</div>

<div class="yesDiv">
<p class="yes">YES</p>
</div>

 

</body>
 
</html>"""