Rick Astley Python Lessons

Posted on October 7th, 2008

Filed under: General — Karl Olson @ 11:50 pm

I’ve mentioned RickRolling before on the blog, and imagine many people have heard about the attempt to get him voted the best act ever. What you might not know is that this attempt at the biggest RickRoll yet has resulted in various scripts and sites to automatically and repeatedly vote for Rick. Well, I started to play with some of the scripts so I could participate in this ridiculous endeavor, and I found the scripts to be lacking. So, what’s a boy to do? Hack together multiple scripts to not only present the information I want, but also to ensure that the number votes I want to register actually registers (not just a certain number of attempts at voting.) Thus, after the break (unless you’re reading this on the nerdcore.info nerdcore metablog, where it’ll just display,) you can see my first python script.

#!/usr/bin/env python
import urllib2
import urllib
import os
num = 1000000 # The number of times to iterate
y = 0 # number of failed iterations
params = {}
params ={'server':'http%3A%2F%2Fcmsema.mtv.co.uk%2Fema2008%2Fxml%2Fvoting%2FquietVote.jhtml','voteFor':'274130150'}
params = urllib.urlencode(params)
for x in range(num + y):
os.system('cls')
print "Iterations: %s" % x,
print "Number of errors: %s" % y,
print "Votes: %s" % (x-y),
req = urllib2.Request(url='', data=params)
try:
urllib2.urlopen(req)
except:
y+=1
print ' (error occured)'
else:
print
# num + y forces it loop as many iterations as it takes to get to num inspite
# of any errors

Paste Bin Version

Not eloquent, but very functional. Thank you to Rick Astley, the Internet and BestActEver.com for getting me back into playing scripts.

Comments (1)

1 Comment

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.