-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (27 loc) · 898 Bytes
/
app.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
from flask import Flask, render_template, request
import os, subprocess
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
def compile_code_os(code_string):
with open("/tmp/temp.c", "w") as f:
f.write(code_string)
os.system("gcc /tmp/temp.c -o /tmp/temp.out")
os.system("chmod +x /tmp/temp.out")
output = subprocess.check_output("/tmp/temp.out", stderr=subprocess.STDOUT).decode()
return output
@app.route("/compile", methods = ['POST'])
def compile_code():
input_code = request.form['input_code']
try:
result = compile_code_os(input_code)
except Exception as e:
print(e)
result = "An error occured during compilation"
return render_template('compile.html', result=result)
@app.route("/d3")
def d3_test():
return render_template('d3_test.html')
if __name__ == "__main__":
app.run()