diff options
Diffstat (limited to 'Web/PI')
-rw-r--r-- | Web/PI/PI.py | 25 | ||||
-rw-r--r-- | Web/PI/Results/results.txt | 2 | ||||
-rw-r--r-- | Web/PI/Uploads/upload.py | 13 | ||||
-rw-r--r-- | Web/PI/test2.py | 6 |
4 files changed, 19 insertions, 27 deletions
diff --git a/Web/PI/PI.py b/Web/PI/PI.py index 5e75298..b607f76 100644 --- a/Web/PI/PI.py +++ b/Web/PI/PI.py @@ -4,9 +4,9 @@ import subprocess import os app = Flask(__name__) -UPLOAD_DESTINATION = "Uploads/upload.py" +UPLOAD_DESTINATION = "Uploads/" -RESULTS_DESTINATION = "Results/results.txt" +RESULTS_DESTINATION = "Results/" @app.route('/') def home(): @@ -18,25 +18,28 @@ def my_test_endpoint(): 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") + 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]) + subprocess.call(["python", UPLOAD_DESTINATION + filename]) # Get results file - with open(RESULTS_DESTINATION, 'r') as results: + results_filename = filename.split(".")[0] + results_filename = results_filename + "_results" + with open(RESULTS_DESTINATION + results_filename, 'r') as results: results_content = results.read() results.close() - - # subprocess.check_output(["echo", "Hello World!"]) - # os.remove(UPLOAD_DESTINATION) - # os.remove(RESULTS_DESTINATION) + + # 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_content':results_content} + dictToReturn = {'results_filename':results_filename, 'results_content':results_content} return jsonify(dictToReturn) if __name__ == '__main__': diff --git a/Web/PI/Results/results.txt b/Web/PI/Results/results.txt deleted file mode 100644 index ce8f671..0000000 --- a/Web/PI/Results/results.txt +++ /dev/null @@ -1,2 +0,0 @@ -THIS IS RESULTS TEXT -Current Time = 21:07:34
\ No newline at end of file diff --git a/Web/PI/Uploads/upload.py b/Web/PI/Uploads/upload.py deleted file mode 100644 index 9cbc73a..0000000 --- a/Web/PI/Uploads/upload.py +++ /dev/null @@ -1,13 +0,0 @@ -import time, os
-from datetime import datetime
-
-now = datetime.now()
-current_time = now.strftime("%H:%M:%S")
-print("Current Time = " + current_time)
-
-f = open("Results/results.txt", "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 index 40bbe9c..a5eb806 100644 --- a/Web/PI/test2.py +++ b/Web/PI/test2.py @@ -1,3 +1,7 @@ import subprocess +import os + subprocess.call(["python", "Uploads/upload.py"]) -print("end of script")
\ No newline at end of file +print("end of script") + +os.remove("Uploads/upload.py")
\ No newline at end of file |