15 Nov

Analyzing sentiments on twitter Part I: Streaming twitter data

Sentiment analysis is a widely studied field in the field of Natural language processing. In this series we try to understand sentiment analysis. We’ll write our own quick-fix sentiment analyzer. In subsequent posts we’ll explore techniques to visualize the social media sentiment.

Streaming Twitter Data

In this post we shall track twitter on a hashtag and push those tweets live to the browser. We assume that you have Node installed. We assume you know how to configure and run an Express web server on node.

npm install node-tweet-stream

This installs node-tweet-stream which lets you stream twitter data on your node server. We push these tweets to the client whenever we receive any tweet. The architecture is as follows:

stream twitter to browser

On the server side we emit the tweet every time we receive it:

We listen for tweets on the client side:

So thats pretty much all you need to do to get a stream of tweets on your browser. Once you have this stream you can add your presentation logic to create visualizations or other fancy stuff with the tweets. You could also do computationally intensive work on tweets on the server and push it the result to the client along with the tweet.