home

More Python and Twitter

After spending 2 days wrestling with urllib2 and status updates, I couldn’t figure out what was wrong. It just wouldn’t post a tweet. Fortunately, on google code there’s a library for interfacing with twitter that makes it pretty easy. I quite like the idea of a Terminal client for twitter, so I’ll probably finish writing Twitterminal, but I won’t be half as proud of it as if I’d managed to get it working with urllib2. Oh well.

On a sidenote, Textmate is literally awesome. I’ve done a lot of customising it in the last day and the bundles are actually encouraging me to document my code (probably too) fully.

google python textmate twitter twitterminal urllib2

code, internet

this many: 2! (that's loads)

Binny V A:

Here is a small python script I use to get my friends’ status…

#!/usr/bin/python

import urllib
from xml.dom import minidom

username = “binnyva”
password = “password_goes_here”

friends_timeline_url = “http://”+username+”:”+password+”@twitter.com/statuses/friends_timeline.xml”
public_timeline_url = “http://twitter.com/statuses/public_timeline.xml” #Not used

dom = minidom.parse(urllib.urlopen(friends_timeline_url))

for status in dom.getElementsByTagName(“status”):
user_name = status.getElementsByTagName(“name”)[0].firstChild.data
tweet = status.getElementsByTagName(“text”)[0].firstChild.data
created_at = status.getElementsByTagName(“created_at”)[0].firstChild.data.split(“+”)[0]

print user_name, “: \”" + tweet + “\” at ” + created_at + “\n”

To post tweets, I use the Command Line Twitter Client

Jasper Tandy:

Thanks – the main thing I was trying to do was use urllib/urllib2 to wrap around the Twitter API and take care of all of that. I’ve done it now, but I’ve stopped using Twitter as I can’t really be bothered with a site that is so unreliable!

I’ll upload my Twitter thing at some point as I quite like the way it works, but it’s not polished, just literally a CLI for interfacing with Twitter.