-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
79 lines (66 loc) · 3.43 KB
/
server.py
File metadata and controls
79 lines (66 loc) · 3.43 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
# -*- coding: utf-8 -*-
import cherrypy
import mysql.connector
import os
import ExerciseManager as EM
class Root(object):
@cherrypy.expose
def __init__(self):
open("home.html","r").read()
@cherrypy.expose
def form(self):
cherrypy.response.headers["Content-Type"] = "text/html"
return open("form1.html","r").read()
@cherrypy.expose
def index(self):
print(os.getcwd())
return open("home.html","r").read()
@cherrypy.expose
def Exercises(self):
with open('headerexercises', 'r') as myfile:
head = myfile.read().replace('\n', '')
print(head)
exlist = []
exlist = EM.genindex()
print(exlist)
for x in range(0,len(exlist)):
head = head +"<form method=\"post\" action=\"Question\"> <button type=\"submit\" value=\""+str(exlist[x].id)+"\" name=\"value\" class=\"btn btn-primary\">Exercise"+" "+str(exlist[x].id+1) +"</button></form> "
head = head + "</div><div class=\"col-sm-2\"></div></div></div></body></html>"
return head
@cherrypy.expose
def Question(self,value):
with open('headerexercicio.html', 'r') as myfile:
head = myfile.read().replace('\n', '')
print(head)
exlist = []
exlist = EM.genindex()
print(exlist)
ans = exlist[int(value)].w
ans.append(exlist[int(value)].correct)
a = exlist[int(value)].img;
img_name = a.split('/')
img_name = img_name[-1]
q = EM.createQuestion(exlist[int(value)]);
head = head + " "+str(exlist[int(value)].id + 1) + "</h1>" "<p>" + q+ "</p>"
head = head +"<p> </<p>"+"<img class=\"mx-auto text-center\" src=images/"+str(img_name)+" height=\"220\ witdh=\"520\">" + "<form>"
for x in range(0,len(ans)):
head = head +" <input type=\"radio\" name=\"value\" value=\""+str(ans[x])+"\" >" +str(ans[x]) + " " + str(exlist[int(value)].types) +"<br>"
head = head + "</form>"
head = head + "<form method=\"post\" action=\"Exercisees\"> <button type=\"submit\" value=\""+str(value)+"\" name=\"value\" class=\"btn btn-primary\"> Solution </button></form>"+"</div><div class=\"col-sm-2\"></div></div></div></body></html>"
return head
@cherrypy.expose
def Exercisees(self,value):
with open('headerexercicio.html', 'r') as myfile:
head = myfile.read().replace('\n', '')
exlist = []
exlist = EM.genindex()
a = exlist[int(value)].img;
img_name = a.split('/')
img_name = img_name[-1]
return head+" "+str(exlist[int(value)].id + 1) + "</h1>" +"<p> </<p>"+"<img class=\"mx-auto text-center\" src=images/"+str(img_name)+" height=\"220\ witdh=\"520\">"+"<p> </p>"+ exlist[int(value)].expl
if __name__ == "__main__":
conf = {'/images': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join('/home/ele/resources/ExerciseImage')}}
cherrypy.config.update({'server.socket_host': '0.0.0.0',
'server.socket_port': 8888}) #muda a porta para 8081 o 0.0.0.0 significa que ele está à espera de comandos a partir de qualquer interfa$
cherrypy.quickstart(Root(),'/',config=conf) #lança o servidor