-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·59 lines (51 loc) · 2.08 KB
/
__init__.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
from flask import Flask, request, render_template, url_for, jsonify, send_file, Response, make_response, send_from_directory, session, safe_join
from flask.sessions import SessionInterface
import os, subprocess
from datetime import datetime
from secrets import path
import main
execfile(path+"evaluation/column_testing.py")
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = path+'uploaded/'
app.config['OUTPUT_FOLDER'] = path+'output/'
app.config['ALLOWED_EXT'] = set(['csv','json'])
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXT']
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/process', methods=['POST'])
def process():
for i in range(len(request.files)):
f = request.files['file'+str(i)]
if f and allowed_file(f.filename):
now = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
noExt, ext = os.path.splitext(f.filename);
filename = os.path.join(app.config['UPLOAD_FOLDER'], noExt+now+ext)
f.save(str(filename));
main.execute(filename)
outputFile = noExt+now+".txt"
r = make_response(send_file(app.config['OUTPUT_FOLDER'] + outputFile), 200, {"file": outputFile} );
return r;
elif f:
return "wrong file extension"
return "No files were uploaded"
@app.route('/evaluate', methods=['POST'])
def evaluate():
for i in range(len(request.files)):
f = request.files['file'+str(i)]
if f and allowed_file(f.filename):
now = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
noExt, ext = os.path.splitext(f.filename);
filename = os.path.join(app.config['UPLOAD_FOLDER'], noExt+now+ext)
f.save(str(filename));
evaluator = column_type_tester(filename)
output = evaluator.entry_test()
r = make_response(output );
return r;
elif f:
return "wrong file extension"
return "No files were uploaded"
if __name__ == '__main__':
app.run(debug=True)