From c65005de4f64b590188b48bc76e7e20420213e98 Mon Sep 17 00:00:00 2001 From: Christie Ewen Date: Thu, 28 Jan 2016 14:58:20 -0500 Subject: [PATCH] Update recipe.py Thanks to HelloWorld and Games Brainiac via StackOverflow http://stackoverflow.com/questions/29698799/alchemyapi-recipes-twitter-doesnot-work-properly --- recipe.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe.py b/recipe.py index 86235f0..31e31c6 100644 --- a/recipe.py +++ b/recipe.py @@ -298,10 +298,10 @@ def print_results(): most_positive_tweet = tweets.find_one({"sentiment" : "positive"}, sort=[("score", -1)]) most_negative_tweet = tweets.find_one({"sentiment" : "negative"}, sort=[("score", 1)]) - mean_results = tweets.aggregate([{"$group" : {"_id": "$sentiment", "avgScore" : { "$avg" : "$score"}}}]) + mean_results = list(tweets.aggregate([{"$group" : {"_id": "$sentiment", "avgScore" : { "$avg" : "$score"}}}])) - avg_pos_score = mean_results['result'][2]['avgScore'] - avg_neg_score = mean_results['result'][1]['avgScore'] + avg_pos_score = mean_results['result'][1]['avgScore'] + avg_neg_score = mean_results['result'][0]['avgScore'] print "SENTIMENT BREAKDOWN" print "Number (%%) of positive tweets: %d (%.2f%%)" % (num_positive_tweets, 100*float(num_positive_tweets) / num_tweets)