Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Create a new Twitter app by navigating to https://apps.twitter.com.

  2. 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 and OAUTH_CONSUMER_SECRET respectively. Most Unix-based systems with sh-compatible shells support the export command:

    $ export OAUTH_CONSUMER_KEY="Your OAuth Consumer...