aboutsummaryrefslogtreecommitdiffstats
path: root/Web
diff options
context:
space:
mode:
authorDat Nguyen <nguy2854@umn.edu>2019-11-21 14:16:52 -0600
committerDat Nguyen <nguy2854@umn.edu>2019-11-21 14:16:52 -0600
commitd126a9ea02c1edceff30efa6fe0e061c2c19062a (patch)
tree41111d48b7193428c1307d8a956a7cf2be2d7459 /Web
parentremoved unnecessary (diff)
downloadee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar.gz
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar.bz2
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar.lz
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar.xz
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.tar.zst
ee4511w-d126a9ea02c1edceff30efa6fe0e061c2c19062a.zip
tabs to spaces smh
Diffstat (limited to '')
-rw-r--r--Web/PI/Uploads/test.py17
-rw-r--r--Web/Server/Server.py84
2 files changed, 59 insertions, 42 deletions
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/Server/Server.py b/Web/Server/Server.py
index 45f06b0..ce695fb 100644
--- a/Web/Server/Server.py
+++ b/Web/Server/Server.py
@@ -19,62 +19,62 @@ PI_URL = 'http://localhost:8000'
RESULTS_DESTINATION = "Results/results.txt"
def allowed_file(filename):
- return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
-
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
+
@app.route('/')
def home():
- return render_template('index.html')
+ return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
- if request.method == 'POST':
+ if request.method == 'POST':
# Check if the post request has the file part
- if 'file' not in request.files:
- flash('No file part')
- return redirect(request.url)
+ if 'file' not in request.files:
+ flash('No file part')
+ return redirect(request.url)
- # Grab the file
- file = request.files['file']
- if file.filename == '':
- flash('No file selected for uploading')
- return redirect(request.url)
+ # Grab the file
+ file = request.files['file']
+ if file.filename == '':
+ flash('No file selected for uploading')
+ return redirect(request.url)
- # Send the file content as a post to the PI
- if file and allowed_file(file.filename):
+ # Send the file content as a post to the PI
+ if file and allowed_file(file.filename):
- dictToSend = {'filename':file.filename, 'file_content':file.read()}
- file.close
- print('Running test')
- flash('Running test')
- response = requests.post(PI_URL + '/tests/endpoint', json=dictToSend)
-
- results_filename = json.loads(response.text)[u'results_filename']
- results_content = json.loads(response.text)[u'results_content']
- flash('Results file:' + results_filename)
- flash('Response from server:' + results_content)
-
- results = open(RESULTS_DESTINATION, "w")
- results.write(results_content)
- results.close()
+ dictToSend = {'filename':file.filename, 'file_content':file.read()}
+ file.close
+ print('Running test')
+ flash('Running test')
+ response = requests.post(PI_URL + '/tests/endpoint', json=dictToSend)
+
+ results_filename = json.loads(response.text)[u'results_filename']
+ results_content = json.loads(response.text)[u'results_content']
+ flash('Results file:' + results_filename)
+ flash('Response from server:' + results_content)
+
+ results = open(RESULTS_DESTINATION, "w")
+ results.write(results_content)
+ results.close()
- return render_template('index.html', results = 'True')
- else:
- flash('Allowed file types are .py')
- return redirect(request.url)
+ return render_template('index.html', results = 'True')
+ else:
+ flash('Allowed file types are .py')
+ return redirect(request.url)
@app.route('/results', methods=['GET'])
def download():
- # Grab content from results file
- with open(RESULTS_DESTINATION, 'r') as results:
- results_content = results.read()
- results.close()
+ # Grab content from results file
+ with open(RESULTS_DESTINATION, 'r') as results:
+ results_content = results.read()
+ results.close()
- # Put content as a download file
- return Response(
- results_content,
- mimetype="text/csv",
- headers={"Content-disposition":
- "attachment; filename=results.csv"})
+ # Put content as a download file
+ return Response(
+ results_content,
+ mimetype="text/csv",
+ headers={"Content-disposition":
+ "attachment; filename=results.csv"})
if __name__ == "__main__":
app.run(host="localhost", port=5000) \ No newline at end of file