Bitten by twitter

It was recently that I decided to check out this cool microblogging site thanks to geekandpoke and my friend Swaroop . Twitter has this concept that, when you 'follow' someone, you get know by minute updates on the things that they do. When you 'tweet' it means that you just update what you are doing now. So if I was tweeting now, I would something like 'blogging about twitter'. To know more -> twitter help.


Twittering with python

Twitter is a cool micro blogging site, with many people updating their day to day activities on a minute by minute basis. So what if we could get as well as post updates in a neat way. The possibilities are endless. One possible scenario would be, If you have a firewall, your firewall could 'tweet' every time it is targeted by an attacker. So people around the world( who follow you) would get to know the attack process in real time !!!

Now lets try to programmatically read and then post a few tweets using python.

So lets get started,

The first site would ofcourse be the python section of twitter api library - http://apiwiki.twitter.com/Libraries#Python

In the next 4 steps, lets see how we could post a tweet in twitter

1. First download the wrapper python twitter.

2. Run > cmd. Go to the folder where you have downloaded python twitter( as mentioned in step 1 ) and Fire up python

3. Type
>>> import twitter

4. If you want to get latest tweets of someone, then the type the following

>>> client = twitter.Api()
>>> latest_posts = client.GetUserTimeline("yourusername")
>>> print [s.text for s in latest_posts]

5. If you want to post your own tweets, then type the following

>>> client = twitter.Api(username='yourusername', password='yourpassword')
>>> update = client.PostUpdate('The Twitter API is easy')


Other cool twitter api wrappers

Hang on buddies, more updates coming soon.

Labels: