Hasin Vai has a good post about collecting tweets in real time with php. Here’s the post: http://hasin.wordpress.com/2009/06/20/collecting-data-from-streaming-api-in-twitter/ 🙂 If you are a php developer look into there.
Well, I am going to cover Python for the Twitter streaming API. You need the “tweetstream” python module which depends on the “anyjson” module. Please make sure you have these modules installed before you proceed.
Download Links: anyjson | tweetstream
To install these packages, use the built in setup.py of the individual packages :
1 |
sudo python setup.py install |
In my case, I didn’t have the “setuptools” python module installed with my default python installation. So I had to install it to get the setup.py work:
1 |
sudo apt-get install python-setuptools |
I love the magic of debian packages 🙂
Now, you can install the modules and dive into our example:
1 2 3 4 5 6 7 8 9 10 |
#! /usr/bin/env python import tweetstream stream = tweetstream.TweetStream("twitter_username", "twitter_password") for tweet in stream: if tweet.has_key("text"): print tweet['user']['screen_name'] + ": " + tweet['text'] , "\n" print "-----" * 4 |
That’s it! In real, you get the stream dictionary which you can use to manipulate the tweets.
The “tweetstream” module also lets you access the Track and Follow APIs in a superb fashion!
I love Twitter, I love Python! 🙂