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! 🙂
9 replies on “Twitter Streaming API with Python”
[…] This post was mentioned on Twitter by python ism, Abu Ashraf Masnun. Abu Ashraf Masnun said: Twitter Streaming API with Python: http://bit.ly/4nPlv4 #Python #Twitter […]
[…] the rest here: Twitter Streaming API with Python « maSnun.com By admin | category: python | tags: api, installed-before, make-sure, module-which, […]
Hi that is a genuinely interesting view, It does give one food for thought, I am very delighted I stumbled on your blog, i was using Stumbleupon at the time, in any case i don?t want to ramble on too much, but i would like to say that I will be back when I have a little time to read your blog more thoroughly, Once again thanks a lot for the blog post and please do keep up the right work,
Having setuptools installed, you could just use
sudo easy_install tweetstream
and get tweetstream and all it’s dependencies installed automatically (just like using Apt-get or Yum).
And thanks for sharing this, btw. : )
Awesome! But do you have an easy way to have it write the raw tweetstream data to a file?
I didn’t try!
Try this – uses tweepy http://blog.yeleek.co.uk/2012/07/python-owl/
tweepy also shows tweets in real time?