diff options
author | Raspberry Pi <raspberrypi@umn.edu> | 2019-11-21 16:15:35 -0600 |
---|---|---|
committer | Raspberry Pi <raspberrypi@umn.edu> | 2019-11-21 16:15:35 -0600 |
commit | 85b09cd608f0c0a4c7e7c84555f8d053d324e64c (patch) | |
tree | 15ea472af07615c756e53582958e54ae37ff8b2b /Web/PI | |
parent | Rework directory structure. Modify result file printing to match requirements... (diff) | |
parent | requirements (diff) | |
download | ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.gz ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.bz2 ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.lz ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.xz ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.tar.zst ee4511w-85b09cd608f0c0a4c7e7c84555f8d053d324e64c.zip |
Merge branch 'master' of https://github.umn.edu/damic014/ee4950-inverted-pendulum
Diffstat (limited to '')
-rw-r--r-- | Web/PI/PI.py | 48 | ||||
-rw-r--r-- | Web/PI/Results/PLACEHOLDER.txt | 0 | ||||
-rw-r--r-- | Web/PI/Uploads/PLACEHOLDER | 0 | ||||
-rw-r--r-- | Web/PI/Uploads/test.py | 17 | ||||
-rw-r--r-- | Web/PI/test2.py | 7 |
5 files changed, 72 insertions, 0 deletions
diff --git a/Web/PI/PI.py b/Web/PI/PI.py new file mode 100644 index 0000000..a6a597b --- /dev/null +++ b/Web/PI/PI.py @@ -0,0 +1,48 @@ +#handle a POST request +from flask import Flask, render_template, request, url_for, jsonify +import subprocess +import os +app = Flask(__name__) + +UPLOAD_DESTINATION = "Uploads/" + +RESULTS_DESTINATION = "Results/" + +@app.route('/') +def home(): + return "ANDI'S PIE" + +@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 + filename=input_json['filename'].encode("ascii") + file_content=input_json['file_content'].encode("ascii") + upload = open(UPLOAD_DESTINATION + filename, "w") + upload.write(file_content) + upload.close() + + # Run python script + subprocess.call(["python", UPLOAD_DESTINATION + filename]) + + # Get results file + results_filename = filename.split(".")[0] + results_filename = results_filename + "_results.csv" + with open(RESULTS_DESTINATION + results_filename, 'r') as results: + results_content = results.read() + results.close() + + # Remove test file and results file now that were done with them + os.remove(UPLOAD_DESTINATION + filename) + os.remove(RESULTS_DESTINATION + results_filename) + + # Return results file content + dictToReturn = {'results_filename':results_filename, 'results_content':results_content} + return jsonify(dictToReturn) + +if __name__ == '__main__': + app.run(host="localhost", port=8000) + # UNCOMMENT IF RUNNING PI.PI ON PI + #app.run(host="192.168.1.10", port=8000) diff --git a/Web/PI/Results/PLACEHOLDER.txt b/Web/PI/Results/PLACEHOLDER.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Web/PI/Results/PLACEHOLDER.txt diff --git a/Web/PI/Uploads/PLACEHOLDER b/Web/PI/Uploads/PLACEHOLDER new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Web/PI/Uploads/PLACEHOLDER diff --git a/Web/PI/Uploads/test.py b/Web/PI/Uploads/test.py new file mode 100644 index 0000000..5091e89 --- /dev/null +++ b/Web/PI/Uploads/test.py @@ -0,0 +1,17 @@ +import time, os, sys
+from datetime import datetime
+
+file_name = os.path.basename(sys.argv[0])
+
+file_name = file_name.split(".")[0]
+
+now = datetime.now()
+current_time = now.strftime("%H:%M:%S")
+print("Current Time = " + current_time)
+
+f = open("Results/" + file_name + "_results", "w+")
+f.write("THIS IS RESULTS TEXT\n")
+f.write("Current Time = " + current_time)
+f.close()
+print("Running test.py for ~ 5 seconds.")
+time.sleep(5)
diff --git a/Web/PI/test2.py b/Web/PI/test2.py new file mode 100644 index 0000000..a5eb806 --- /dev/null +++ b/Web/PI/test2.py @@ -0,0 +1,7 @@ +import subprocess +import os + +subprocess.call(["python", "Uploads/upload.py"]) +print("end of script") + +os.remove("Uploads/upload.py")
\ No newline at end of file |