Created
September 24, 2013 09:52
-
-
Save Eckankar/6682635 to your computer and use it in GitHub Desktop.
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
| #!/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