Twitter through python
Updates are displayed on the user’s profile page and instantly delivered to other users who have signed up to receive them. The sender can restrict delivery to those in his or her circle of friends (delivery to everyone is the default). Users can receive updates via the Twitter website, instant messaging,SMS, RSS, email or through an application.
Now let’s have a look at python and integrate the Twitter with Python. Python-twitter module is a python wrapper around Twitter API which is available at http://code.google.com/p/python-twitter/. The twitter module depends on simplejson module which is available from http://pypi.python.org/packages/source/s/simplejson/simplejson-1.9.1.tar.gz. As it is a pure python implementation, installation is very easy and traditional.
Then download the python-twitter module from http://python-twitter.googlecode.com/files/python-twitter-0.5.tar.gz .
tar zxvf python-twitter-0.5.tar.gz
cd python-twitter
python setup.py build
python setup.py install
and we are done
Now let’s write the simplest python script to post a message in twitter.
###############################################################
# The simplest python program to play with twitter using python-twitter
# Google Code: http://code.google.com/p/python-twitter/
# Google Groups: http://groups.google.com/group/python-twitter
# Python twitter API can be used to send and receive twitter messages
#
# Thanks to DeWitt Clinton <dewitt@google.com> for this wonderful module
#
import twitter
api = twitter.Api(username=”my_twitter_username”, password=”my_secret_password”, input_encoding=None)
status = api.PostUpdate(“example of the simplest twitter message program “)
print status.text
###########################################################
It is very simple. Now let’s run the code as
python simple_twitter.py
example of the simplest twitter message program
Now when I visit my twitter home (http://twitter.com/maxinbjohn), I can see that message and I think it is cool