Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AasemJS
Created March 16, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AasemJS/61c6b5d4927d95548a0419df3b32d9b1 to your computer and use it in GitHub Desktop.
Save AasemJS/61c6b5d4927d95548a0419df3b32d9b1 to your computer and use it in GitHub Desktop.
EmotionDetection
#tweepy framework library for fetching tweets
import tweepy
#textblob to analyse text
from textblob import TextBlob
#importing sys to take arguments from user at runtime
import sys
#search term
search_term = str(sys.argv[1])
# keys and tokens from the Twitter Dev Console
consumer_key = 'CRpwRAQstBnS2wvn9LTTStSdk'
consumer_secret = 'BRE3OZIAKkUI3jy1lNGBfjVcPiKmiLfmsfmBzW9BfXTmvOxU7F'
access_token = '1078866367-u9EDOMFeDeipYVqEWinqsnBBmCqITOXmlU27HIv'
access_secret = '0zxFAe6E5yldd6BgJKeNb6k8kpyf6SbPkxrYL0aJrnSQM'
#Authorization for tweepy to bring tweets from twitter
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_secret)
api = tweepy.API(auth)
#store tweets in variable public_tweets
public_tweets = api.search("%s" % search_term)
#display each tweet separately
for tweet in public_tweets:
print(tweet.text)
analysis = TextBlob(tweet.text)
print ("\n")
print (analysis.sentiment)
print ("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment