469,275 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Poll script in Python

Lad
Is there a poll script available in Python?
Jul 18 '05 #1
9 3905
On 16 Oct 2004 03:59:05 -0700, Lad <ex****@hope.cz> wrote:
Is there a poll script available in Python?


Can you be more specific? Are you talking about socket polling? Or a
web poll? Etc?

-Josh
Jul 18 '05 #2
Is there a poll script available in Python?


What do you mean by "poll"?

Do you mean "poll a file for changes", "poll a file handle for
readability/writability", "poll a socket", ..., "a web poll for taking
surveys",...?

- Josiah

Jul 18 '05 #3
Lad
Josh Close <na****@gmail.com> wrote in message news:<ma**************************************@pyt hon.org>...
On 16 Oct 2004 03:59:05 -0700, Lad <ex****@hope.cz> wrote:
Is there a poll script available in Python?


Can you be more specific? Are you talking about socket polling? Or a
web poll? Etc?

About web poll
Lad
Jul 18 '05 #4
> About web poll

Like: http://www.quizilla.com/
Or: http://slashdot.org/pollBooth.pl?qid=1192&aid=-1

You must be precise.

- Josiah

Jul 18 '05 #5
ex****@hope.cz (Lad) wrote in message news:<81************************@posting.google.co m>...
Josh Close <na****@gmail.com> wrote in message news:<ma**************************************@pyt hon.org>...
On 16 Oct 2004 03:59:05 -0700, Lad <ex****@hope.cz> wrote:
Is there a poll script available in Python?


Can you be more specific? Are you talking about socket polling? Or a
web poll? Etc?

About web poll
Lad


When in doubt, make your own :) !!!
Jul 18 '05 #6
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
Is there a poll script available in Python?


I'm very interested in increasing the range of 'standard' CGI scripts
available in python. If you (or anyone else ?) wants help in writing a
simple one that could be used as a plugin to other webpages then
contact me and we'll work on it.

Regards,

Fuzzyman

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #7
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
Is there a poll script available in Python?

Sure!
Jul 18 '05 #8
ma**********@gmail.com (Matthew K Jensen) wrote
When in doubt, make your own :) !!!

That seems wasteful, although I admit that finding something that
exactly suits you can be hard. I looked around for survey software a
while ago and didn't find any that worked for me, so I wrote some,
called Theodolite. If you are interested in the blurb at
http://joshua.smcvt.edu/theo, I'd be glad for beta tester feedback
(This is not a permanent address: I haven't yet had the chance to
upload the material to a Sourceforge-like site. If you mail me, I'll
tell you how to get it.)

Jim
Jul 18 '05 #9
fu******@gmail.com (Michael Foord) wrote in message news:<6f**************************@posting.google. com>...
ex****@hope.cz (Lad) wrote in message news:<81*************************@posting.google.c om>...
Is there a poll script available in Python?


I'm very interested in increasing the range of 'standard' CGI scripts
available in python. If you (or anyone else ?) wants help in writing a
simple one that could be used as a plugin to other webpages then
contact me and we'll work on it.


Here's some code (with organization-specific stuff replaced by
asterisks) that I wrote for polls that use ranked ballots:

# vote.cgi

#!/usr/bin/python

import os

def printError(message):
print ' <p>%s</p>\n </body>\n</html>' % message

def ordinal(n):
if n == 1:
return str(n) + 'st'
if n == 2:
return str(n) + 'nd'
if n == 3:
return str(n) + 'rd'
if n < 20:
return str(n) + 'th'
return ordinal(n % 10)

def printBallot():
candidates = file('CANDIDATES').read().splitlines()
n = len(candidates)
print ' <form method="post" action="castvote.cgi" />'
print ' <table>'
print ' <tr>'
print ' <th>Candidate</th>'
for i in xrange(1, n + 1):
print ' <th>%s choice</th>' % ordinal(i)
print ' </tr>'
for (candidateNumber, candidateName) in enumerate(candidates):
print ' <tr>'
print ' <td class="candidate">%s</td>' %
candidateName
for i in xrange(1, n + 1):
print ' <td>'
print ' <input type="radio" name="rank-%d" '
\
'value="%d"' % (candidateNumber,
i),
if i == n:
print 'checked',
print '/>'
print ' </td>'
print ' </tr>'
print ' </table>'
print ' <p class="votesubmission">'
print ' <input type="submit" value="Submit Ballot" />'
print ' </p>'
print ' </form>'
print ' </body>'
print '</html>'

print '''Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=us-ascii" />
<link rel="stylesheet" type="text/css" href="../****/style.css"
/>
<title>Vote!</title>
</head>
<body>'''
address = os.environ['REMOTE_ADDR']
if address.startswith(****):
try:
ballots = file('BALLOTS').read()
except IOError:
ballots = ''
if (address + '\n') in ballots:
printError('This isn\'t Chicago. You\'re only allowed to vote
once.')
else:
printBallot()
else:
printError('You can only vote from within ****')

# castvote.cgi

#!/usr/bin/python

import cgi
import os

address = os.environ['REMOTE_ADDR']
form = cgi.FieldStorage()
ballot = []
i = 0
while True:
try:
ballot.append(int(form['rank-%d' % i].value))
except KeyError:
break
i += 1

f = file('BALLOTS', 'a')
f.write('%r # %s\n' % (ballot, address))
f.close()

print '''Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=us-ascii" />
<link rel="stylesheet" type="text/css" href="../****/style.css"
/>
<title>Vote Submitted</title>
</head>
<body>
<p>Thank you for voting in ****'s ****. Results will be
announced at
****.</p>
<p>Click <a href="../****">here</a> to return to the
website.</p>
</body>
</html>'''
Jul 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Michael | last post: by
17 posts views Thread by Doug Holton | last post: by
4 posts views Thread by Mario | last post: by
1 post views Thread by Magnus Lycka | last post: by
2 posts views Thread by beliavsky | last post: by
5 posts views Thread by pbd22 | last post: by
2 posts views Thread by inhahe | last post: by
1 post views Thread by Jean-Paul Calderone | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.