Book Image

Mastering Python for Data Science

By : Samir Madhavan
Book Image

Mastering Python for Data Science

By: Samir Madhavan

Overview of this book

Table of Contents (19 chapters)
Mastering Python for Data Science
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Estimating the Likelihood of Events
Index

Performing sentiment analysis on world leaders using Twitter


Before we start analyzing tweets, we'll need to install the Twython package of Python, which helps interact with the Twitter API to get tweets from Twitter. This can be downloaded from https://github.com/ryanmcgrath/twython.

Also, you need to get the consumer key and consumer secret key from https://apps.twitter.com/app/new.

Once you have details about your app, you'll get the consumer key and consumer secret key:

After this, go to the Key and Access Tokens tab to generate your access token:

Once you have the required keys, we'll add the details to the following code:

#Please provide your keys here

TWITTER_APP_KEY = 'XXXXXXXXXXXXXXXXXXXXX' 
TWITTER_APP_KEY_SECRET = 'XXXXXXXXXXXXXXXXXXXXX'  
TWITTER_ACCESS_TOKEN = 'XXXXXXXXXXXXXXXXXXXXX' TWITTER_ACCESS_TOKEN_SECRET = 'XXXXXXXXXXXXXXXXXXXXX' 

t = Twython(app_key=TWITTER_APP_KEY, 
           app_secret=TWITTER_APP_KEY_SECRET, 
           oauth_token=TWITTER_ACCESS_TOKEN, 
         ...