-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
39 lines (32 loc) · 960 Bytes
/
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
# Importing required libraries
import os
import random
import string
from flask import *
from extract import formToData
# Set react build folder for static and template
app = Flask(
__name__,
static_folder=os.path.abspath("frontend/build/static"),
template_folder=os.path.abspath("frontend/build"),
)
# Server react site at root
@app.route("/")
def hello():
return render_template("index.html")
# Api for form to data
@app.route("/api/uploadForm", methods=["POST"])
def success():
if request.method == "POST":
f = request.files["file"]
randomStr = "".join(random.choices(string.ascii_letters, k=5))
filePath = os.path.abspath("upload/" + randomStr + f.filename)
f.save(filePath)
formData = formToData(filePath)
os.remove(filePath)
return formData
else:
return {"status": "failed"}
# Start flask server
if __name__ == "__main__":
app.run(debug=False, port=5016)