The github link for the code is given below:
https://github.com/AlchemyAPI/alchemyapi-recipes-twitter
I get the following error when I run recipe.py:
Traceback (most recent call last):
File "recipe.py", line 340, in <module>
main(sys.argv[1], int(sys.argv[2]))
File "recipe.py", line 43, in main
print_results()
File "recipe.py", line 303, in print_results
avg_pos_score = mean_results['result'][2]['avgScore']
TypeError: 'CommandCursor' object has no attribute '__getitem__'
I am using python version 2.7.6 Please do help me out to solve this.
Yeah, I finally got the correct output.Thanks to Games Brainiac for helping me to figure it out.
mean_results = list(tweets.aggregate([{"$group" : {"_id": "$sentiment",
"avgScore" : { "$avg" : "$score"}}}]))
avg_pos_score = mean_results[1]['avgScore']
avg_neg_score = mean_results[0]['avgScore']
The mean_results will contain a list of dictionary entities(in this case 3 entities-neg,pos,neutral). So mean_results[0] refers to the negative entity. mean_results[1] refers to the positive entity. and so on. mean_results[1]['avgScore]=avg score of the positive entity. and so on...