-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtocweb.py
44 lines (32 loc) · 1.11 KB
/
tocweb.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
import contextlib
import io
from tug_overlap_checker import tug_overlap_checker
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def form():
return render_template('form.html')
@app.route('/result', methods=['POST', 'GET'])
def result():
if request.method == 'POST':
# Get the submitted course IDs
text = request.form['text']
lines = text.split('\n')
lines = [l.strip() for l in lines]
print(lines)
f = io.StringIO()
with contextlib.redirect_stdout(f):
tug_overlap_checker.main(raw_args=lines)
output = f.getvalue()
print("captured: {}".format(output))
# CBA'd changing it in toc
output = output.replace("[93m", "<font color=\"indianred\"><b>")
output = output.replace("[0m", "</b></font>")
return render_template('result.html', result=output)
elif request.method == 'GET':
text = "ERROR: Fill out form on main page"
return render_template('result.html', result=text)
def main():
app.run(debug=True)
if __name__ == '__main__':
main()