from flask import Flask, request
from interface import annotate
from flask_cors import CORS
from flask import jsonify
from utils.fileio import load_json

app = Flask("PrivacyScan")

cors = CORS(app, resources={r"/scan": {"origins": "*"}})


@app.route("/scan", methods=['POST'])
def scan():
    print(request.get_json())
    source = request.get_json()['source']
    entire = request.get_json()['entire']
    data_type = request.get_json()['dataType']
    purpose_dict = request.get_json()['purpose']
    data_type = load_json(data_type)
    purpose_dict = load_json(purpose_dict)
    lattice = {'dataType': data_type, 'purpose': purpose_dict}
    result = annotate(source, lattice,
             entire)
    print(source)
    return jsonify(result)


if __name__ == '__main__':
    app.run(host="0.0.0.0",post=5000,debug=True)
