python-twitter vs Google App Engine

Posted on May 16, 2008

In preparation for tackling Wazup, I started learning a little bit about Python (I know many people have said this already, but Dive Into Python is a really good book!) and I decided to try out a much smaller (and hopefully easier) app to begin with.
So I began coding a little toy that does some stuff with my twitter friends list.

I’m using python-twitter and the app is coming along nicely, except…

Well, like I said earlier, I’m something of an old-hand at programming and my first instinct when learning a new language or tackling a new kind of problem is to first get it working on the command-line and then get the code to work on the web (or whatever happens to be my intended platform). Yes, and my IDE is vim OK?

So what’s the big deal, you may ask?

When I ported my app, which was running perfectly on the command-line, into the App Engine development platform it started bombing, complaining about not being able to get the current user.

Say what?? Well, one thing I’m more than used to is to debug stuff, even in languages I don’t master. And this was very easy to do actually, so I got to the point really fast: python-twitter assumes you’re running on a real machine and implements a caching mechanism that assumes you have such things as a tmp dir where you can store your temporary files.
The code was trying to determine who I was in order to find out where it should store it’s temporary cache files.

Of course in a sandboxed environment such as the App Engine, there is no such thing as disk-based storage (or even system users for that matter), so it was failing miserably.

Turns out that someone else had already been there and the way to work around this is to modify python-twitter and make it use App Engine’s own datastore for the caching. That is if I do think it needs caching at all, I’m still not too sure about that.

Oh well, my first project to “ease” myself \into the language and already I’m making changes to other people’s code…

It’s been fun, though, I must admit to that!