#!/usr/bin/python import cgi, os from polldata import * def save(): file = open('polldata.py', 'w') file.write('byIP = %s\ncomment = %s' % (`byIP`, `comment`)) file.close() factor, total, span, pres = 10, 0.0, 0, { 1: ('George Washington', 90), 2: ('John Adams', 48), 3: ('Thomas Jefferson', 96), 4: ('James Madison', 96), 5: ('James Monroe', 96), 6: ('John Quincy Adams', 48), 7: ('Andrew Jackson', 96), 8: ('Martin Van Buren', 48), 9: ('William Henry Harrison', 1), 10: ('John Tyler', 47), 11: ('James Knox Polk', 48), 12: ('Zachary Taylor', 16), 13: ('Millard Fillmore', 32), 14: ('Franklin Pierce', 48), 15: ('James Buchanan', 48), 16: ('Abraham Lincoln', 49), 17: ('Andrew Johnson', 47), 18: ('Ulysses S. Grant', 96), 19: ('Rutherford B. Hayes', 48), 20: ('James Garfield', 6), 21: ('Chester Alan Arthur', 42), 22: ('Grover Cleveland', 96), 23: ('Benjamin Harrison', 48), 24: ('William McKinley', 54), 25: ('Theodore Roosevelt', 90), 26: ('William Howard Taft', 48), 27: ('Woodrow Wilson', 96), 28: ('Warren G. Harding', 29), 29: ('Calvin Coolidge', 67), 30: ('Herbert Hoover', 48), 31: ('Franklin Roosevelt', 145), 32: ('Harry Truman', 95), 33: ('Dwight D. Eisenhower', 96), 34: ('John F. Kennedy', 34), 35: ('Lyndon Johnson', 62), 36: ('Richard Nixon', 66), 37: ('Gerald Ford', 30), # 38: ('Jimmy Carter', 48), 39: ('Ronald Reagan', 96), # 40: ('George Bush', 48), # 41: ('Jackass', 96), # 42: ('George W. Bush', 48 + 48?), } print 'Content-type: text/html' print ( """ Dead President Ratings
"Is This One?"

Rate the Dead Presidents!

""") form = cgi.FieldStorage() if form.has_key('guy'): guy = int(form['guy'].value) if form.has_key('vote'): if form.has_key('confirm'): IP = os.environ['REMOTE_ADDR'] if not byIP.has_key(IP): byIP[IP] = {} byIP[IP][guy] = int(form['vote'].value) save() else: print ( """

Please Confirm Your Vote


""") % (guy,form['vote'].value,form['vote'].value,pres[guy][0]) raise SystemExit elif form.has_key('comment'): if form.has_key('name') and form.has_key('email'): if not comment.has_key(guy): comment[guy] = [] entry = [ form['name'].value, form['email'].value, form['comment'].value ] if entry not in comment[guy]: comment[guy].append(entry) save() if 0: mail = os.popen("/usr/sbin/sendmail -t manus-prez", 'w') mail.write('From: %s (%s)\nSubject: %s\nTo: %s\n\n%s' % (form['email'].value, form['name'].value, 'Dead President Comment (%s)' % pres[guy][0], 'manus-prez@python.net', form['comment'].value)) mail.close() print ( """

Thank You!
Your Comment Has Been Noted


...And wow! It is now possible for you to receive each and every comment in your e-mail as soon as they are submitted. If you would like to have this happen for you, just say (well, e-mail) the word! """) else: print ( """

' You Did Not Specify Your Name or E-Mail Address!
Your Comment Was Not Added


""") else: print '

Comments About %s


' % pres[guy][0] if comment.has_key(guy): for remark in comment[guy]: print ('
') if type(remark[1]) == type('') and '@' in remark[1]: print '%s:' % (remark[1], remark[0]) else: print '%s:' % remark[0] print '
%s

' % remark[2] else: print ( """

' No Comments Have Yet Been Entered


""") print ( """

Add Your Own Comment

Note: If you are the person who has decided that it is entertaining to post obscenity here, you should know that I have your IP address, online times, and other information it takes to have you booted from your Internet service. I suggest you think twice. Spray paint your own walls if you want to make yourself laugh using your favorite four letter words. It's a sad form of entertainment, but to each his own, I suppose.

Your Name:
Your E-Mail Address:
Your Comment:
""" % guy) raise SystemExit print ( """ Here is your chance to see how the Dead Presidents rate, and your chance to spout off for your favorite or least favorite. Cast your vote for any of the men using the scale from negative five to positive five, with zero being "average." Look at what your fellow Dead Presidents fans have to say about each of the Chief Executives, and add your own two bits.

This is about as scientific as any other Internet poll (which means, it's not scientific at all). One vote per person per President, please (this is mildly enforced, so you shouldn't be able to make a mistake and pump someone's rating higher or lower). This is a democracy, after all. [Well, the nation is a democratic republic, but this poll is a democracy. ...With a touch of tyranny, since I will personally edit all profanity out of any comments you leave.]

Think it's fun talking about Dead Presidents? You're not alone. Check out DP's on DP's, a litany of comments about their fellows, made by the Dead Presidents themselves.
""") print '

' keys = pres.keys() keys.sort() for item in [0] + keys + [0]: print '' if item == 0: for i in ['President', 'Votes', 'Rating']: print '' % rate rate = 10 * factor - rate if rate: print '' % rate print '' print '' print ( """
%s' % i for val in ['-4', '-3', '-2', '-1', '-0', '+0', '+1', '+2', '+3', '+4']: print ('%s' % (factor, val)) print 'VoteComments' else: rating = count = 0 for IP in byIP.keys(): rating = rating + byIP[IP].get(item, 0) count = count + byIP[IP].has_key(item) if count: rating = rating / float(count) print '%s' % pres[item][0] print '%d' % count print '%+.2f' % rating total, span = total + rating * pres[item][1], span + pres[item][1] rate = round(rating * factor) + (5 * factor) if rate: print '

' print '' print '
' print '' % item print '' else: print 'value="%3d To Read">' % len(comment[item]) print '

Given the ratings above,
and factoring the time served in office by each man,
the average Dead President rates at %+.2f

""") % (6 + factor * 10, total / span)