Automatically updating my blog by using Twitterrific

December 19, 2008

I’ve been working on a new blogging system that brings my Twitter stream to my home page. I had a few goals in mind when I first set upon this endeavor. The features I really wanted were:

  1. Update my blog when I post to Twitter.
  2. Expand tweets that start with special tags (such as #blog, #img, #yt, #code).
  3. Generate an archive page that allows you to see any of my past tweets.

It was fairly trivial to address points 2 and 3. I wrote a simple Python script that pulled XML versions of my twitter statuses using the API. This script will look at the created_at time of the last tweet pulled and then use that time + 1 second to pull the most recent tweets. Expanding tweets was also fairly easy. I follow a protocol of “#hashtag Words That Make Up The Title < link to thing to expand >”. The archive page was also easy to create. I simply create a nested dictionary for entries grouped by year, month, day and then turned this into a nested HTML list.

However, after all of this automation I was still doing something very annoying. I posted to Twitter and then used Quicksilver to run a Python script on my server. I’m a Twitterrific user and I didn’t want to change my method of posting and viewing tweets. At the same time, I couldn’t figure out how to automatically run the Python update script as I posted the tweet. And then I saw this post on the ProteusX forum which led me to peek into the Twitterrific.app directory and find an Applescript that could be called everytime I update my Twitter status. The script is the one used for updating iChat (/Applications /Twitterrific.app /Contents /Resources /UpdateChatStatus.scpt). From this point it was simple enough to tell Twitterrific to update iChat (which I don’t use) and replace the guts of the script that would do this with a command to run my existing blogging script.

So this:

    on update_status(message)

        tell application "System Events" to set processNames to name of processes

        set iChatRunning to processNames contains "iChat"
        if (iChatRunning) then
            tell application "iChat"
                set status message to message
            end tell
        end if

    end update_status

became:

    on update_status(message)

        run script file "Macintosh HD:Users:nirmal:Library:Scripts:blog.scpt"

    end update_status

And for those that are curious blog.scpt looks like:

    tell application "Quicksilver"
        show large type (do shell script "ssh -i /Users/nirmal/.ssh/blog user@nirmalpatel.com")
    end tell

The ssh key used is only allowed to ssh into my server and run the Python script that pulls the most recent tweet from Twitter. So this solution allows me to run the script from Quicksilver, if I don’t update from Twitterrific for some reason, and also allows Twitterrific to update my website with the added benefit of showing me a success/error message in large type.

I’m not sure if this is the best way to solve goal #1 but it definitely works for me.

permalinkarchive

View Comments