The Bird is the Word

Twitter's apparently the rage these days. I've decided to get into it by posting updates to this site, pushes to my Github, and other code-related things, automatically on Twitter.

This is harder than it sounds, mostly because Twitter's API is tricky to work with, and also partially due to confusing and faulty tools. I'm going to outline the basic steps I took to make my Twitter integration work, and also point out that this took me days. For comparison, my RSS feed took me around two minutes to implement, test, and deploy. (Oh, did I mention? I have an RSS feed now!)

First things first. In Python, there are a few different libraries available to do Twitter API calls. Confusingly, they all have the same module name, twitter, meaning that this statement is frustratingly ambiguous:

>>> import twitter

Which library did I just import?

The most common one is called python-twitter and it is usually available as a package of the same name in your distro of choice. At least Debian (and Ubuntu), Fedora, and Gentoo (via an overlay) have it. This is not the right library. In about a week, Twitter will turn off the basic authentication, totally disabling most deployed versions of this library.

Instead, use the Python Twitter Tools. This package, available on PyPI as twitter, works with the newer OAuth system being deployed on Twitter, and will work into the future.

So, OAuth. This is kind of tricky, and I'm not going to go into the gory details. Suffice it to say that you need two pairs of keys: A consumer pair, from Twitter's API service, and a token pair, from the user you're going to post tweets as. To get consumer keys, you will need to go to http://dev.twitter.com/apps and register a new application. Make sure you specify Client access instead of Browser access. Now, go back to your Python shell, and do the following:

>>> import twitter.oauth_dance
>>> app_name = "my application" # use the info from the twitter app
>>> key = "mumbo-jumbo" # the consumer key
>>> secret = "secret-agent-man" # and the consumer secret
>>> twitter.oauth_dance.oauth_dance(app_name, key, secret)

Follow the instructions, and you'll get a tuple containing your token key and secret. Now just add the following to your client and you'll be set!

# Obviously, these are not real keys! Follow the instructions above to get
# real keys.
consumer_key = "mumbo-jumbo"
consumer_secret = "secret-agent-man"
token_key = "number-with-random-letters"
token_secret = "mission-impossible"
oauth = twitter.OAuth(token_key, token_secret,
    consumer_key, consumer_secret)
twitter.Twitter(auth=oauth).statuses.update(status=message)

The library follows the same pattern as the official Twitter API, so this is equivalent to requesting statuses/update.json with a status parameter.

~ C.

Created on Aug 09, 2010

Last modified on Aug 09, 2010

Come Together

I have cleaned out all of my old files from my code-related domain and put them up on my Github. Only two things were really still relevant.

The Tiger Python module is on my Github, as a brand-new project, tiger. It was broken, but I fixed it to work again and added a few tests as well. I even tagged version 0.2 as tiger-0.2 in the repository.

The Compiz wallpaper script, for assigning files to the wallpapers in compiz, is also alive and well. I did not test it since I do not have a Compiz setup at the moment, but I think that it still works as well as it did before, which of course is to say "not at all." At any rate, it is in my madsnippets repository.

With these changes, code.corbinsimpson.com is ready to be retired, so I am taking it offline. Nobody will be affected. Thank you for your patience.

~ C.

Created on Jul 05, 2010

Last modified on Aug 07, 2010

Maiden Voyage

Things have changed a bit around here, and hopefully for the better. I've replaced my old Drupal stack with a fairly slimmed-down piece of code based on the terrific Bottle framework. Over the next few weeks, I will try to talk a lot more about the stuff I've been working on, including code, music, and other things.

Hopefully this site is a lot easier to look at than the old site. Feel free to drop me a line if you find any problems!

~ C.

Created on Jun 25, 2010

Last modified on Aug 07, 2010

Hardware Store

I have put the list of video cards I own up on the Xorg wiki, see http://x.org/wiki/CorbinSimpson for the full list.

~ C.

Created on Jun 21, 2010

Last modified on Aug 07, 2010

Valid CSS!