Created
January 9, 2010 18:51
-
-
Save sherbondy/273036 to your computer and use it in GitHub Desktop.
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
def load_tumblr(user, tries=2): | |
url = "http://" + user + ".tumblr.com/api/read/json?type=photo&num=20&tagged=project" | |
try: | |
result = urlfetch.fetch(url) | |
""" tumblr outputs the json as a javascript var, so we have to remove | |
junk at the beginning and the semicolon at the end.""" | |
content = result.content.replace("var tumblr_api_read = ", "") | |
content = content[:-2] | |
js_object = json.loads(content) | |
return js_object | |
except ValueError: | |
if tries > 0: | |
load_tumblr(user, tries-1) | |
else: | |
print "Attempts exceeded, failed to load tumblr." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment