def runLiveSentimentAnalysis(keyword, maxTweets=300, maxTime=0, backup=10): maxTweets = int(maxTweets) maxTime = int(maxTime) backup = int(backup) Creds = loadCreds() CONSUMER_KEY = Creds['CONSUMER_KEY'] CONSUMER_SECRET = Creds['CONSUMER_SECRET'] OAUTH_TOKEN = Creds['OAUTH_TOKEN'] OAUTH_TOKEN_SECRET = Creds['OAUTH_TOKEN_SECRET'] auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, retry_count=10, retry_delay=5, retry_errors=5) twitterStream = Stream(auth=api.auth, listener=listener(count, maxTweets, maxTime, backup)) twitterStream.filter(track=[keyword]) if settings["datalog"] == True: writeToFile(tweetJSON, 'live-sentiment') while plt.fignum_exists(1): plt.show() plt.pause(0.0001) return tweetJSON
import tweepy #The Twitter API from time import sleep from datetime import datetime from textblob import TextBlob #For Sentiment Analysis import matplotlib.pyplot as plt #For Graphing the Data from settingHandler import loadSettings from writeFile import writeToFile from loadCreds import loadCreds Creds = loadCreds() CONSUMER_KEY = Creds['CONSUMER_KEY'] CONSUMER_SECRET = Creds['CONSUMER_SECRET'] OAUTH_TOKEN = Creds['OAUTH_TOKEN'] OAUTH_TOKEN_SECRET = Creds['OAUTH_TOKEN_SECRET'] auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET) api = tweepy.API(auth) def runSentimentAnalysis(keyword, tweetNumber=100, backup=10): if backup == '0': backup = '1' tweetNumber = int(tweetNumber) polarity_list = [] numbers_list = [] number = 1 settings = loadSettings() tweetJSON = {}