47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
#!/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')
|
|
|
|
log("Receiving Tweet to classify {}".format(tweet), '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'}
|
|
|
|
def callSentimentAnalyser():
|
|
analyser.set_newSentiment()
|
|
|
|
app.run(port=9090, host="0.0.0.0")
|
|
|
|
def callProbes():
|
|
runFlaskProbes()
|
|
|
|
if __name__ == '__main__':
|
|
setup_logging()
|
|
|
|
log("Starting Spam Filter...", 'INFO')
|
|
sys.stdout.flush()
|
|
|
|
Thread(target=callProbes).start()
|
|
|
|
Thread(target=callSentimentAnalyser).start()
|
|
# Thread(target=callNewsFilter).start() |