diff options
author | Dat Nguyen <nguy2854@umn.edu> | 2019-11-20 21:10:51 -0600 |
---|---|---|
committer | Dat Nguyen <nguy2854@umn.edu> | 2019-11-20 21:10:51 -0600 |
commit | 8887dc5a9803969e23b24eb293711c1e32c374e5 (patch) | |
tree | bd287ae89568ef18f4fa05e604f94dc28148bcb1 /Web/PI/PI.py | |
parent | Remove leftover files from a past merge. (diff) | |
download | ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar.gz ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar.bz2 ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar.lz ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar.xz ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.tar.zst ee4511w-8887dc5a9803969e23b24eb293711c1e32c374e5.zip |
Web stuff semi working
Diffstat (limited to '')
-rw-r--r-- | Web/PI/PI.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Web/PI/PI.py b/Web/PI/PI.py new file mode 100644 index 0000000..ae01bf3 --- /dev/null +++ b/Web/PI/PI.py @@ -0,0 +1,39 @@ +#handle a POST request +from flask import Flask, render_template, request, url_for, jsonify +import subprocess +import os +app = Flask(__name__) + +UPLOAD_DESTINATION = "Uploads/upload.py" + +RESULTS_DESTINATION = "Results/results.txt" + +@app.route('/tests/endpoint', methods=['POST']) +def my_test_endpoint(): + # Receive post + input_json = request.get_json(force=True) + + # Put file content into a file caled upload.py + file_content=input_json['file_content'] + upload = open(UPLOAD_DESTINATION, "w") + upload.write(file_content) + upload.close() + + # Run python script + subprocess.call(["python", UPLOAD_DESTINATION], shell=True) + + # Get results file + with open(RESULTS_DESTINATION, 'r') as results: + results_content = results.read() + results.close() + + # subprocess.check_output(["echo", "Hello World!"]) + # os.remove(UPLOAD_DESTINATION) + # os.remove(RESULTS_DESTINATION) + + # Return results file content + dictToReturn = {'results_content':results_content} + return jsonify(dictToReturn) + +if __name__ == '__main__': + app.run(host="localhost", port=8000)
\ No newline at end of file |