-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
107 lines (77 loc) · 2.68 KB
/
server.py
File metadata and controls
107 lines (77 loc) · 2.68 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from datetime import date
from datetime import datetime
from flask import Response
from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
import json
from videos import readVideo
from questions import readQuestion, readSeenQuestions
from translator import translateText
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/practice")
def practice():
return render_template("practice.html")
@app.route("/progress")
def progress():
return render_template("progress.html")
@app.route("/signup")
def signup():
return render_template("signup.html")
@app.route("/videoList")
def videoList():
return render_template("videoList.html")
@app.route("/practicePage")
def practicePage():
info = readQuestion()
question = [i for i in info.values()][0]
trans = translateText(question)
return render_template("practicePage.html", question=question + trans)
@app.route("/receive", methods=['post'])
def recieve():
files = request.files
file = files['file']
filename = file.filename
with open("static/videos/"+filename, 'wb') as f:
f.write(file.read())
response = jsonify("File received and saved!")
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/update", methods=['post'])
def update():
message = json.loads(request.data, strict=False)
file = 'static/videos/userHistory.json'
listObj = []
with open(file) as fp:
listObj = json.load(fp)
listObj.append({
"FILENAME": message['FILENAME'],
"QUESTION": str(message['QUESTION'])
})
with open(file, 'w') as json_file:
json.dump(listObj, json_file, indent=4, separators=(',',': '))
with open("static/userData.json") as fp:
listObj = json.load(fp)
current = listObj['TOTAL']
listObj.update({"TOTAL": str(int(current)+1)})
with open("static/userData.json", 'w') as json_file:
json.dump(listObj, json_file, indent=4, separators=(',',': '))
response = jsonify("File received and saved!")
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/getUserData", methods=['put'])
def getUserData():
print("HI")
return jsonify("File received and saved!")
@app.route("/checkGrammar", methods = ['push'])
def checkGrammar():
#ADD PYTHON CODE TO RUN
response = jsonify("File received and saved!")
response.headers.add('Access-Control-Allow-Origin', '*')
return response
if __name__ == "__main__":
app.run(debug=True)