#!/usr/bin/env python import sys, json sys.path.append('/home/sentiment-analyser/') from threading import Thread from src.utils.jsonLogger import setup_logging, log import analyser.sentimentAnalyser as sentimentAnalyser from flask import Flask, request from probes.probes import runFlaskProbes app = Flask(__name__) analyser = sentimentAnalyser.get_sentiment() @app.route('/sentiment', methods=['GET']) def tweetPredict(): tweet = request.args.get('tweet') syncId = request.headers.get('X-CRYPTO-Sync-ID') log("Receiving Tweet to classify [{}] for [{}]".format(tweet, syncId), 'INFO') result = analyser.get_vader_sentiment(tweet) log("Returning classification result of [{}]".format(result), 'INFO') return json.dumps({'result': result, 'tweet': tweet}), 200, {'ContentType':'application/json'} @app.route('/sentimentProbeTest', methods=['GET']) def sentimentProbeTest(): return json.dumps({'result': {'Score': {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}, 'Compound': 0.0}, 'tweet': 'Fake Text'}), 200, {'ContentType':'application/json'} def callSentimentAnalyser(): analyser.set_newSentiment() app.run(port=9090, host="0.0.0.0") def callProbes(): runFlaskProbes() if __name__ == '__main__': setup_logging() log("Starting Sentiment Analyser...", 'INFO') sys.stdout.flush() Thread(target=callProbes).start() Thread(target=callSentimentAnalyser).start()