Streaming Twitter for real-time sentiment analysis
Twitter is flooded with content that arrives every second. A great way to start investigating real-time data is by examining tweets.
This recipe will show how to write code that reacts to tweets relating to a specific search query. We use an external web-endpoint to determine whether the sentiment is positive, neutral, or negative.
Getting ready
Install the twitter-conduit
package:
$ cabal install twitter-conduit
For parsing JSON, let's use yocto
:
$ cabal install yocto
How to do it…
Follow these steps to set up the Twitter credentials and begin coding:
- Create a new Twitter app by navigating to https://apps.twitter.com.
- Find the OAuth Consumer Key and OAuth Consumer Secret from this Twitter Application Management page. Set the environmental variables on our system for
OAUTH_CONSUMER_KEY
andOAUTH_CONSUMER_SECRET
respectively. Most Unix-based systems with sh-compatible shells support theexport
command:$ export OAUTH_CONSUMER_KEY="...