Skip to content

Instantly share code, notes, and snippets.



Created Nov 17, 2012
What would you like to do?
Bulk-queueing photo posts on Tumblr
import sys, os.path, shutil
from tumblpy import Tumblpy
oauth_consumer_key = '<oauth consumer key from>'
secret_key = '<secret key from>'
blog_url = '<your tumblr>'
images = [];
for file in sys.argv[1:]:
t = Tumblpy(app_key = oauth_consumer_key, app_secret = secret_key)
auth_props = t.get_authentication_tokens()
oauth_token = auth_props['oauth_token']
oauth_token_secret = auth_props['oauth_token_secret']
auth_url = auth_props['auth_url']
print "Go to this URL: ", auth_url
# Try opening the URL for them
os.system('open "%s"' % auth_url)
# Everyone always talked about PINs... you're looking for the oauth_verifier bit
oauth_verifier = raw_input('Enter oauth_verifier from browser: ')
t = Tumblpy(app_key = oauth_consumer_key, app_secret = secret_key,
oauth_token=oauth_token, oauth_token_secret=oauth_token_secret)
authorized_tokens = t.get_authorized_tokens(oauth_verifier)
final_oauth_token = authorized_tokens['oauth_token']
final_oauth_token_secret = authorized_tokens['oauth_token_secret']
t = Tumblpy(app_key = oauth_consumer_key, app_secret = secret_key,
oauth_token=final_oauth_token, oauth_token_secret=final_oauth_token_secret)
for image in images:
photo = open(image, 'rb')
# You could customize params if you want to add a caption/title/other stuff... or even queue other kinds of posts
post ='post', blog_url=blog_url, params={'type':'photo', 'state':'queue', 'data': photo})
if (post):
print "Queued: ", image, "Post: ", post
shutil.move(image, image[:-4] + "_done" + image[-4:]);
# We'll probably get an exception and never get here...
print "Error posting", image;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment