Scott Vanderlind

everything happens so much

Weekday Project: Automated Tumblr Fame?

It's the first week of a new school year, so you know what that means! Getting a head start on procrastination! Now with more selfies!

I have a friend that posts his selfies to Tumblr, and he's wildly successful. His posts often get tens of notes which by Tumblr standards might not seem like a lot, but relative to the 0 notes that my selfies get, it's certainly a lot. I've asked him how he does it, and he simply insists that "It's easy, I just post my selfies, and I've been doing it since high school." How could I have what he has?? I knew I had to at least try it, and I wondered if I could do it totally anonymously on a fresh, unknown blog that consisted of only my selfies and various hashtags.

If you know me you also know that I have a certain fondness for selfies. My Snapchat story is pretty hearty, and I even gave a talk called To Thine Own Selfie be True (PDF of my slides, a video of the talk is coming once I get my hands on it) during my university's CENG (College of Engineering) open house, in which I explain my favorite techniques and antipatterns for taking awesome selfies (as well as a short histroy of the selfie).

Understandibly, I have a lot of selfies. I took a moment and went through my Google backup of my camera roll and hand-picked a folder full of selfies that I had decided I would post to Tumblr. "It'll be a snap!", I though. "I'll be Tumblr-famous in no time."

I soon realized that my hand-picked folder had quickly balooned to over 225 images. Yikes! There was no way that I was going to sit on Tumblr and create 225 posts and tag each one of them with the nearly twenty hashtags that I had determined to be perfect selfie-fodder. That's when the developer inside me kicked in and I remembered the Tumblr API and the convenient, official Python client pytumblr. They say automation is the wave of the future; maybe I can automate my fame as a Tumblr selfie-star?

I had 225 selfies in the folder then, but I'd like to be able to automatically queue more up later. I decided it would be best to write a script to automatically queue up the contents of a folder on my file server and set it as a cron task. That way uploading more selfies would be as easy as dragging-and-dropping the images into the watched folder.

The Script

Writing the script itself went quickly. Yay Python! I set up a folder structure for the project; a working directory with the subfolders selfies and posted, for selfies due to post and selfies already posted, respectively.

The really rough procedure is that we'll set up our Tumblr API client, list the contents of the source directory, and post each file using the Tumblr API. At the end, we move the image to the posted directory.

If you'd like to skip the chatter and jump right to my finished script, you can find it here on Github.

First, let's get the API client pytumblr set up and authorized (you can install this module via pip or easy_install). The Tumblr API is designed to be authenticated against using oAuth1.0a. This is pretty heavy when we're using a short-running command line script since we can't really have web-facing callbacks for tokens and the like, so instead we'll just register our application and then use the interactive API console to authenticate and get a token. Then we can plug our credentials into our client constructor.

client = pytumblr.TumblrRestClient(  
    '<consumer key>',       # Your app's consumer API key
    '<consumer secret>',    # Your app's consumer secret
    '<oauth token>',        # The token you got from the console
    '<oauth secret>',        # The secret you got from the console

Getting a list of our files to post is simple enough.

source_folder = 'selfies'  
files = os.listdir(source_folder)  

Now that we've got a list of the files in the directory, we can iterate over them and create a post.

for file in files:  
    full_path = source_folder + "/" + file
            "someCoolSelfieBlog",       # your blog name
            state = 'queue',            # either 'queue' or 'post'
            tags = ["selfie", "selfies"],
            data = full_path,            # the image file
            caption = "lol selfie!!1!"
        print "Successfully posted " + full_path
    except IOError:
        print "Error! That path was probably a subfolder."

And donezo! I used this to upload all 225 of my selfies into my blog's queue, which will automatically post the photos throughout the day. All the posts have the same tags and caption, or course, but it would be trivial to update the script to dynamically generate the caption.

As an aside, make sure there are only images in your source folder, and double check for hidden files. I didn't notice a hidden file called .DS_Store that my Mac had created and the script posted it to Tumblr just fine. Maybe coincidentally (but maybe not), my Tumblr dash broke for several hours after it had uploaded.


So did it work? I'm still finding out. As of now (the queue has been posting an image every 1.5 hours for 3 days or so), I've managed to gain six followers and get fifty-three total notes (though only two are reblogs) on my 45 posted photos.

tumblr activity

The two selfies with the reblogs have been my favorites from the beginning, which makes me think that people are seeing all of them and just not caring. At least it validates that I know a good selfie when I see one!

The source

I might as well make the full source available to you peeps. So you can find it on Github here! Happy selfie-blogging!

comments powered by Disqus