Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Created September 24, 2013 09:52
Show Gist options
  • Select an option

  • Save Eckankar/6682635 to your computer and use it in GitHub Desktop.

Select an option

Save Eckankar/6682635 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from urllib import urlopen
from random import randint
id_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def gen_id():
id = ""
for i in range(5):
id += id_chars[randint(0, len(id_chars)-1)]
return id
def get_random_imgur():
found_img = False
while not found_img:
id = gen_id()
resp = urlopen('http://i.imgur.com/%ss.png' % id)
if resp.getcode() == 200:
thumbdata = resp.read()
found_img = len(thumbdata) != 503
return 'http://i.imgur.com/%s.jpg' % id
for i in range(5):
print get_random_imgur()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment