def getTweets(candidate, start, end): #get the tweets twitter_counts, dates = GetHourlyTweetsDayRange.hourlyTweets(candidate, start, end) #change Nones to 0's i = 0 for count in twitter_counts: if count == None: twitter_counts[i] = 0 i += 1 #turn hourly counts into daily counts daily_counts = [] i = 0 while i < len(twitter_counts): daily_counts.append(sum(twitter_counts[i:i+23])) i += 24 return daily_counts, dates
def plotTwitter(candidate, start, end): twitter_counts, dates = GetHourlyTweetsDayRange.hourlyTweets(candidate, start, end) #change Nones to 0's i = 0 for count in twitter_counts: if count == None: twitter_counts[i] = 0 i += 1 #turn hourly counts into daily counts daily_counts = [] i = 0 while i < len(twitter_counts): daily_counts.append(sum(twitter_counts[i:i+23])) i += 24 #normalize counts types = AnalysisObjectFactory.createObject("GraphAnalysisNormalized", candidate, "twitter", 'dates go here', daily_counts) daily_counts = types.getlist_para_two() print 'Normalized: ' + str(daily_counts) + '\n' num_counts = len(daily_counts) #generate x-axis x = list(range(0, len(daily_counts))) line, = plt.plot(daily_counts, 'r') plt.xticks(x, dates, rotation = 'vertical') plt.xlim(0, num_counts) plt.gcf().subplots_adjust(bottom=0.20) plt.title('Daily tweet counts and article counts for ' + candidate) global legend legend[0].append(line) legend[1].append('Tweets') return daily_counts