Skip to content

Instantly share code, notes, and snippets.

@sherbondy
Created January 9, 2010 18:51
Show Gist options
  • Save sherbondy/273036 to your computer and use it in GitHub Desktop.
Save sherbondy/273036 to your computer and use it in GitHub Desktop.
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