# Client python microservice for processing json search results
#
import os
import logging
import time
from flask import Flask, abort, jsonify, request


def process(client, data):

    # put here your client processing code
    data_processed = data

    return data_processed


logging.basicConfig(
    format="%(asctime)s - %(levelname)s - %(name)s -   %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO,
)
logger = logging.getLogger(__name__)

app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['DEBUG'] = False

@app.route("/process", methods=['POST'])
def post_process():
    input = request.get_json()
    if 'client' not in input or 'data' not in input:
        abort(500)
    else:
        start = time.time()
        output = process(input['client'], input['data'])
        end = time.time() 
        logger.info('Processing took %d (ms)' % int((end - start)*1000))
        return output

if __name__ == "__main__":
    app.run(host='0.0.0.0')
