Created
August 26, 2012 10:00
-
-
Save sbp/3476758 to your computer and use it in GitHub Desktop.
Use random.org to select an item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Derived from http://pastebin.com/10egeE1a | |
# Original Copyright 2012, Paul | |
# License: Eiffel Forum License 2 | |
import re, urllib | |
def randomorg(max): | |
svcurl = "http://www.random.org/integers/?num=1&min=1&max=%d&col=1&base=10&format=plain&rnd=new" % max | |
u = urllib.urlopen(svcurl) | |
content = u.read() | |
u.close() | |
return int(content) | |
def selector(istr): | |
terms = re.findall('\[[^\]]*\]|\"[^\"]*\"|\S+', istr) | |
tlen = len(terms) | |
if tlen < 2: | |
print "Please provide at least 2 terms." | |
try: result = randomorg(tlen) | |
except IOError: | |
print "Service error." | |
print "I choose: " + terms[result - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment