-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
85 lines (64 loc) · 2.34 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from flask import Flask, render_template, request, redirect, url_for, session
from datetime import datetime
import re
app = Flask(__name__)
app.secret_key = 'your_secret_key'
@app.route('/')
def login():
return render_template('login.html')
@app.route('/index', methods=['GET', 'POST'])
def index():
return render_template('instructions.html')
'''
if request.method == 'POST':
input1 = request.form['input1']
input2 = request.form['input2']
input3 = request.form['input3']
concatenated_string = input1 + input2 + input3
file_name = f'DataFolder/{concatenated_string}.txt'
with open(file_name, 'w') as file:
file.write(f'Name: {input1} {input2}\n')
file.write(f'Grade level: {input3}\n')
file.write('Identifier, Grade, Timestamp, Seconds Spent on Puzzle, Level, Accuracy, Number of Puzzles\n')
# Store file name in session
session['file_name'] = file_name
return redirect(url_for('index'))
else:
return render_template('instructions.html')
'''
@app.route('/level1')
def level1():
return render_template('puzzle1.html')
@app.route('/level2')
def level2():
return render_template('puzzle2.html')
@app.route('/level3')
def level3():
return render_template('puzzle3.html')
@app.route('/dataFolder', methods=['POST'])
def save_data():
'''
data = request.json
value = data.get('value', '')
file_name = session['file_name']
filenameSubstring = file_name.split('/', 1)[-1]
gradeIndex = filenameSubstring.index('.txt') - 1
grade = filenameSubstring[gradeIndex: gradeIndex+1]
identifier = filenameSubstring[:filenameSubstring.index('.txt') - 1]
valueToWrite = identifier + ", " + grade + ", " + datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "," + str(value)
# Ensure value is a string
if not isinstance(valueToWrite, str):
valueToWrite = str(valueToWrite)
# Retrieve file name from session
file_name = session.get('file_name')
if file_name:
# Save the data to the file
with open(file_name, 'a') as file:
file.write('\n' + valueToWrite)
return 'Data saved successfully'
else:
return 'File name not found in session'
'''
if __name__ == '__main__':
app.run(debug=True, port=8000)