-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.py
32 lines (26 loc) · 1.05 KB
/
compiler.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
from flask import Flask, render_template, request, flash
import basic
app = Flask(__name__)
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@app.route("/", methods=['POST', 'GET'])
def home():
if request.method == 'POST':
req = request.form["workspace"].strip()
print(req)
result, error = basic.run('<stdin>', req)
if error:
flash(f'حدث خطأ ما', 'danger')
return render_template('home.html', res=error.as_string(), req=req)
elif result:
if len(result.elements) == 1:
flash(f'نجح الأمر', 'success')
return render_template('home.html', res=repr(result.elements[0]), req=req)
else:
flash(f'نجح الأمر', 'success')
return render_template('home.html', res=repr(result), req=req)
return render_template('home.html')
@app.route("/docs")
def docs():
return render_template('docs.html')
if __name__ == '__main__':
app.run(debug=True)