1 # -*- coding: utf-8 -*-
5 from flask import request
6 from flask_restful import Resource, abort
8 input_error_409 = 'Input must be a list of JSON objects. JSON objects must contain contain key text.'
9 service_error_503 = 'The sentiment analysis service is currently unavailable.'
11 class Analysis(Resource):
13 return "POST a list of JSON objects as content-type: application/json. JSON objects must contain key 'text'.", 405
16 if not request.json or not isinstance(request.json, (list,)):
17 return abort(409, message=input_error_409)
22 if 'text' not in text:
23 return abort(409, message=input_error_409)
24 text_array.append(text['text'])
26 for sentiment_value in indicoio.sentiment(text_array):
27 value += sentiment_value
29 return abort(503, message=service_error_503)
30 sentiment = value/len(text_array)
31 data = {'sentiment': sentiment}