Skip to content

Instantly share code, notes, and snippets.

@plux
Created July 13, 2012 20:40
Show Gist options
  • Save plux/3107328 to your computer and use it in GitHub Desktop.
Save plux/3107328 to your computer and use it in GitHub Desktop.
random_imgur tiny
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