Category Archives: twitter

I love cURL

Sometime, cURL is a useful tools. And useful to download data from the web.
And scripting to download data. It support major protocol, like ftp, http, https. It is useful for testing, stuff too.

I am working on a pet project, involve twitter, I am try to see how it look like so i download a twitter feed using cURL. And it is really easy. Thanks to the twitter REST interface.

curl –basic –user $username:$password http://twitter.com/statuses/user_timeline.json

All in one line, This is for json, if want xml, the replace json with xml. You might want to save it to a file. You can just redirect to a file. Just replace anything start with the $ with the appropriate value.

curl –basic –user $username:$password http://twitter.com/statuses/user_timeline.json > $filename

fun with python: been twitter’ing with python

I’m not sure why, but python developer seems have ways to write python modules, to integrate with web service. Which to me interesting. There is one from google to integrate, google service. There is one for flickr, which I covered. Etc. Even twitter have one.

The twitter python binding can be found in
http://code.google.com/p/python-twitter/
Before you install it, you need to install simplejson.
http://cheeseshop.python.org/pypi/simplejson

To install simplejson, it is just get the tar.gz file. Then uncompress it,
Then in the same directory
On ubuntu:

sudo python setup.py install

on other linux as root:

python setup.py install

same on windows. just:

python setup.py install

The process of installing the python-twitter is the same cycle of python setup.py

There is a few standard thing we can do with the python-twitter module.

here I assume that, you run it, in a python shell, it is just a follow along tutorial here, and the >>> is not shown:
before that, import the module

import twitter

start using it, you need to authenticate yourself, using your twitter username and password.

api=twitter.Api(“username”,”password”)

to view public time line

status=api.GetPublicTimeline()
for s in status:
print s.text

or you can just

status=api.GetPublicTimeline()
print [s.text for s in status]

to view a user status, just replace user with the username of the user

userStatus=api.GetUserTimeline(“user”)

then read it by

print [t.text for t in userStatus]

Here is the important one, to post your own status using the python-twitter module

posting=apt.PostUpdate(“your status”)

There you go, few way to use python to interface with twitter. You can use this with a gui front end, or integrate with django, etc.