Skip to content

Instantly share code, notes, and snippets.

@lanrat
Created April 27, 2014 06:45
Show Gist options
  • Save lanrat/11339121 to your computer and use it in GitHub Desktop.
Save lanrat/11339121 to your computer and use it in GitHub Desktop.
Print something random
#!/usr/bin/env python
import urllib2
import urllib
import re
def randomThing():
randomURL="http://en.wikipedia.org/wiki/Special:Random"
req = urllib2.Request(randomURL)
res = urllib2.urlopen(req)
finalurl = res.geturl()
decoded = urllib.unquote(finalurl)
endpath = decoded[decoded.rfind('/')+1:]
thing = endpath.replace('_', ' ')
simpleThing = output = re.sub('\(\w*\)', '', thing)
return simpleThing
print randomThing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment