Created
July 13, 2012 20:40
-
-
Save plux/3107328 to your computer and use it in GitHub Desktop.
random_imgur tiny
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
import os, random, string, sys, urllib2 | |
num_pics = 5 | |
if len(sys.argv) > 1: | |
num_pics = int(sys.argv[1]) | |
while num_pics > 0: | |
name = ''.join(random.sample(string.letters+string.digits, 5)) + '.jpg' | |
img = urllib2.urlopen("http://i.imgur.com/" + name).read() | |
if len(img) != 503: # 'image not found' is 503 bytes | |
num_pics -= 1 | |
with open(os.path.join('output', name), "wb") as f: | |
f.write(img) | |
print "downloaded", name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment