Created
July 12, 2012 17:42
-
-
Save roddds/3099573 to your computer and use it in GitHub Desktop.
imgurroulette
This file contains 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
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