Skip to content

Instantly share code, notes, and snippets.

@roddds
Created July 12, 2012 17:42
Show Gist options
  • Save roddds/3099573 to your computer and use it in GitHub Desktop.
Save roddds/3099573 to your computer and use it in GitHub Desktop.
imgurroulette
import urllib2
import random
import sys
ext = ['.png', '.jpg', '.gif']
chars = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
prefix = 'http://i.imgur.com/'
try:
print "Press Ctrl+C to end!"
while True:
code = ''.join([random.choice(chars) for x in range(0, 5)])
filename = code+random.choice(ext)
url = prefix+filename
print 'Trying to download', url,
image = urllib2.urlopen(url).read()
if len(image) == 669:
print "...invalid url"
else:
with open(filename, 'wb') as f:
f.write(image)
print '...download successful!'
except KeyboardInterrupt:
print 'Done!'
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment