-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·69 lines (52 loc) · 2.07 KB
/
main.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
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
#!/usr/bin/python3
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
import subprocess
import shlex
app = Flask(__name__)
host ="https://instructions.pythonanywhere.com/"
app.config["UPLOAD_FOLDER"] = "/home/instructions/dic/static/dic_temp_files/"
@app.route('/')
def upload_file():
return render_template('index.html')
@app.route('/display', methods = ['GET', 'POST'])
def save_file():
if request.method == 'POST':
f = request.files['file']
global filename
filename = secure_filename(f.filename)
f.save(app.config['UPLOAD_FOLDER'] + filename)
subprocess.call(shlex.split('bash /home/instructions/dic/dic.sh ' + app.config['UPLOAD_FOLDER'] + str(filename)))
return render_template('contenthome.html')
@app.route('/instructions_api', methods=['POST'])
def ins_api():
if request.method == 'POST':
f = request.files['file']
global filename
filename = secure_filename(f.filename)
f.save(app.config['UPLOAD_FOLDER'] + filename)
subprocess.call(shlex.split('bash /home/instructions/dic/dic.sh ' + app.config['UPLOAD_FOLDER'] + str(filename)))
a = host + app.config['UPLOAD_FOLDER'] + filename + '_analysis'
i = host + app.config['UPLOAD_FOLDER'] + filename + '_ins'
c = host +app.config['UPLOAD_FOLDER'] + filename + '_chart'
return {"analysis": a,
"Instruction": i,
"Chart": c
}
@app.route('/analysis')
def analysis():
ana = open(app.config['UPLOAD_FOLDER'] + filename + '_analysis',"r")
contentana = ana.read()
return render_template('content.html', content=contentana)
@app.route('/ins')
def ins():
ins = open(app.config['UPLOAD_FOLDER'] + filename + '_ins',"r")
content = ins.read()
return render_template('content.html', content=content)
@app.route('/chart')
def chart():
chart = open(app.config['UPLOAD_FOLDER'] + filename + '_chart',"r")
contentchart = chart.read()
return contentchart
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug = True)