1 # -*- coding: utf-8 -*-
5 from flask import Flask, request
6 from flask_restful import Resource, Api
11 indicoio.config.api_key = '525f16078717a430f9dac17cdc9dbaa3'
13 class Sentiment_Analysis(Resource):
15 return "correct usage: curl -H 'content-type: application/json' -X POST http://localhost:8081 -d '$your JSON here$'"
21 #possible performance improvement: batch sentiment: indicoio.sentiment($list_of_texts$)
22 sentiment_value = indicoio.sentiment(tweet['text'])
23 value += sentiment_value
24 #returns number between 0 and 1.
25 #it is a probability representing the likelihood that the analyzed text is positive or negative
26 #values > 0.5 indicate positive sentiment
27 #values < 0.5 indicate negative sentiment
28 return value/len(tweets)
30 api.add_resource(Sentiment_Analysis, '/')
32 if __name__ == '__main__':
33 app.run(host="0.0.0.0", port=8081, debug=False)