-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
131 lines (96 loc) · 2.59 KB
/
Copy pathapp.py
File metadata and controls
131 lines (96 loc) · 2.59 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from flask import Flask, render_template,request
import flask
import string
import commands
import json
import re
app = Flask(__name__)
@app.route("/")
def main():
return render_template('index.html')
@app.route("/predictSolution.html", methods = ['GET'])
def predictSolutionHTML():
return render_template('predictSolution.html')
@app.route("/tagProblem", methods = ['POST'])
def tagProblem():
# get problem id from form element
problem=request.form['probid']
s=commands.getoutput("python tagProblem.py "+problem)
print s
lines=s.split("\n")
n=0
for i in lines:
n+=1
s=lines[n-1]
print 'response will be '+s
return flask.Response(s,mimetype="text/html")
@app.route("/predictSolution", methods = ['POST'])
def predictSolution():
# get code from form element
code=request.form['code']
# write code to temp file
newfile=open('temp','w')
newfile.write(code)
newfile.close()
s=commands.getoutput("python predict.py")
lines=s.split("\n")
n=0
for i in lines:
n+=1
s=lines[n-1]
return flask.Response(s,mimetype="text/html")
@app.route("/recommend", methods = ['POST'])
def recommend():
# get problem id from form element
# print request.form.keys()
problem=request.form['problemid']
print '---------------'
print problem
s=commands.getoutput("python recommend.py "+problem)
print s
lines=s.split("\n")
n=0
for i in lines:
n+=1
r={}
r[0]=lines[n-3]
r[1]=lines[n-2]
r[2]=lines[n-1]
prob={}
section={}
i=0
while i<3:
#processing the problem id
reg = re.compile("([0-9]+)([a-zA-Z]+)")
m = reg.match(r[i])
prob[i] = m.group(1)
section[i] = m.group(2)
i+=1
s=commands.getoutput("python storeSourceCodes.py "+r[0]+" "+r[1]+" "+r[2])
print s
s=commands.getoutput("python sanitize.py")
print s
return render_template('recommend.html',prob=problem,prob1=prob[0],prob2=prob[1],prob3=prob[2],sec1=section[0],sec2=section[1],sec3=section[2])
@app.route("/hints.html", methods = ['POST'])
def hintsHTML():
prob=request.form['problemid']
return render_template('hints.html',probid=prob)
@app.route("/logicalErrors", methods = ['POST'])
def logicalErrors():
# get code from form element
code=request.form['code']
# write code to temp file
newfile=open('Sol1.c','w')
newfile.write(code)
newfile.close()
s=commands.getoutput("python logical.py")
return flask.Response(s,mimetype="text/html")
@app.route("/generateHint1", methods = ['POST'])
def generateHint1():
problem=request.form['probid']
print "id= "+problem
s=commands.getoutput("python findTricks.py "+problem)
print s
return flask.Response(s,mimetype="text/html")
if __name__ == "__main__":
app.run()