-FROM alpine:latest
+FROM python:3
+LABEL maintainer="Sebastian Steiner"
+
+RUN pip install flask
+RUN pip install flask_restful
+RUN pip install indicoio
+
+WORKDIR /app
+COPY . /app/
+
+RUN chmod a+x *.py
+
+CMD ["python3", "./sentiment_analysis.py"]
--- /dev/null
+# -*- coding: utf-8 -*-
+import json
+import indicoio
+
+from flask import Flask, request
+from flask_restful import Resource, Api
+
+app = Flask(__name__)
+api = Api(app)
+
+indicoio.config.api_key = '525f16078717a430f9dac17cdc9dbaa3'
+
+class Sentiment_Analysis(Resource):
+ def get(self):
+ return "correct usage: curl -H 'content-type: application/json' -X POST http://localhost:8081 -d '$your JSON here$'"
+
+ def post(self):
+ tweets = request.json
+ value = 0
+ for tweet in tweets:
+ #possible performance improvement: batch sentiment: indicoio.sentiment($list_of_texts$)
+ sentiment_value = indicoio.sentiment(tweet['text'])
+ value += sentiment_value
+ #returns number between 0 and 1.
+ #it is a probability representing the likelihood that the analyzed text is positive or negative
+ #values > 0.5 indicate positive sentiment
+ #values < 0.5 indicate negative sentiment
+ return value/len(tweets)
+
+api.add_resource(Sentiment_Analysis, '/')
+
+if __name__ == '__main__':
+ app.run(host="0.0.0.0", port=8081, debug=False)