-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (66 loc) · 2.27 KB
/
app.py
File metadata and controls
82 lines (66 loc) · 2.27 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
from flask import Flask, request, render_template, flash, Response, jsonify
import os
import json
import subprocess
import time
# from werkzeug import secure_filename
app = Flask(__name__)
app.config['SESSION_TYPE'] = 'memcached'
app.config['SECRET_KEY'] = 'super secret key'
CROPPED_IMG_PATH = ".\\static\\FILES\\CROPPED_IMG"
upload_path = ".\\static\\FILES\\PROCESSING_FILE"
District = "District"
City = "City"
Ward = "Ward"
with open("information.json") as file:
info = json.load(file)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/upload", methods = ["POST"])
def upload():
status = "success"
if(request.method == "POST"):
try:
file = request.files["my_file"]
path = os.path.join(upload_path, file.filename)
file.save(path)
except:
flash("ERROR: Please upload file")
status = "fail"
District = request.form['pdfDistrict']
City = request.form["pdfCity"]
Ward = request.form["pdfWard"]
if District == "" or City == "" or Ward == "":
flash("ERROR: Fill information properly")
status = "fail"
if status == "fail":
return render_template("index.html")
command = f"python extract.py {District} {City} {Ward}"
print("Arguments: ", District, City, Ward, end="\n\n")
return render_template("success.html", state = status, location = path, command = command)
''''
@app.route("/result")
def result():
return render_template("result.html", image = os.listdir(CROPPED_IMG_PATH), info= info)
@app.route("/output", methods = ['GET'])
def output():
yield "Processing..."
process = subprocess.Popen(
['python','extract.py', str(District), str(City), str(Ward)],
shell=True,
)
output = process.communicate()
return output
'''
from flask_socketio import SocketIO
socketio = SocketIO(app)
@socketio.on('run_command')
def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
for line in iter(process.stdout.readline, ''):
socketio.emit('output', {'data': line.strip()})
process.stdout.close()
process.wait()
if(__name__=="__main__"):
app.run(debug=True)