-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstarter.py
37 lines (26 loc) · 1.16 KB
/
starter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""This file starts the microservice"""
import os
#!flask/bin/python
from flask import Flask, json, jsonify, logging, request
import classification_facade
with open('./config.json') as config_file:
CONFIG = json.load(config_file)
app = Flask(__name__)
###########################
# receives a json payload containing a list of tweets
# the payload json has to contain at least a list of tweets of which each contains at least the following fields:
# text : string
# status_id : string
# processes and classifies the raw tweets
# classifies the processed data
###########################
@app.route("/hitec/classify/domain/tweets/lang/<string:lang>", methods=["POST"])
def post_classification_result(lang):
app.logger.debug('/hitec/classify/domain/tweets/lang/{} called'.format(lang))
# app.logger.debug(request.data.decode('utf-8'))
tweets = json.loads(request.data.decode('utf-8'))
processed_tweets = classification_facade.process_tweets(tweets, lang)
# app.logger.debug(classified_tweets)
return jsonify(processed_tweets)
if __name__ == "__main__":
app.run(debug=False, threaded=False, host=CONFIG['HOST'], port=CONFIG['PORT'])