-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.py
65 lines (54 loc) · 2.34 KB
/
webapp.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
import os
from flask import Flask, request, redirect, url_for, render_template, flash
from werkzeug.utils import secure_filename
from flask import send_from_directory
from datetime import datetime
from prosupadm import ProSupADM
UPLOAD_FOLDER = '/home/pocs/Documents/usp/tcc/webapp/files'
IMAGES_FOLDER = '/home/pocs/Documents/usp/tcc/webapp/images'
ALLOWED_EXTENSIONS = set(['tsv'])
app = Flask(__name__, static_url_path="/images",
static_folder="images")
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.secret_key = "trabalho de tcc,dsf.usp"
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'arquivotsv' not in request.files:
flash('Nenhum arquivo presente.')
return redirect(request.url)
file = request.files['arquivotsv']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('Nenhum arquivo selecionado.')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(
datetime.now().strftime("%H%M%S%f") + file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'],
filename))
return redirect(url_for('uploaded_file',
filename=filename))
else:
flash("Arquivo com extensão incorreta. Envie um arquivo \
TSV com os dados da captura como descrito no TCC.")
return render_template('adm.html')
@app.route('/adm/<filename>')
def uploaded_file(filename):
adm_file = os.path.join(app.config['UPLOAD_FOLDER'], filename)
image_file = filename.rsplit('.', 1)[0] + ".jpg"
if not os.path.exists(adm_file):
flash("Resultado inexistente, envie seu arquivo novamente.")
return redirect("/")
psadm = ProSupADM()
psadm.analyse(adm_file, url_for('static', filename=image_file)[1:])
return render_template('resultado.html', image=image_file,
admpronation=psadm.adm_pronation, admsupination=psadm.adm_supination,
admtotal=psadm.adm_total)
if __name__ == "__main__":
app.run()