1 # -*- coding: utf-8 -*-
5 from flask import Flask, request, jsonify, Response
6 from flask_restful import Resource, Api, output_json, abort
11 indicoio.config.api_key = '525f16078717a430f9dac17cdc9dbaa3'
13 input_error_409 = 'Input must be a list of JSON objects. JSON objects must contain contain key text.'
14 service_error_503 = 'The sentiment analysis service is currently unavailable.'
16 class Sentiment_Analysis(Resource):
18 return "POST a list of JSON objects as content-type: application/json. JSON objects must contain key 'text'.", 405, {'Allow': 'GET'}
21 if not request.json or not isinstance(request.json, (list,)):
22 return abort(409, message=input_error_409)
27 if 'text' not in text:
28 return abort(409, message=input_error_409)
29 text_array.append(text['text'])
31 for sentiment_value in indicoio.sentiment(text_array):
32 value += sentiment_value
34 return make_error(503, message=service_error_503)
35 sentiment = value/len(text_array)
36 data = {'sentiment': sentiment}
39 api.add_resource(Sentiment_Analysis, '/')
41 if __name__ == '__main__':
42 app.run(host="0.0.0.0", port=8081, debug=False)