-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.py
45 lines (33 loc) · 1.11 KB
/
app.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
from flask import Flask, request, jsonify, render_template
import os
import datetime
import uuid
import main
app = Flask(__name__)
# path to upload files
UPLOAD_FOLDER = 'UPLOAD_FOLDER/'
# route to uploading pdf file
@app.route('/file/upload', methods=['POST'])
def index():
if request.method == 'POST':
# saving current timestamp
current_time = str(datetime.datetime.now()).replace('-', '_').replace(':', '_')
ID = uuid.uuid4().hex
# setting filename that is being received to current time stamp with its directory
filename = UPLOAD_FOLDER + ID + '/' + current_time + '.pdf'
# if the uuid folder doesn't already exist, create it
if not os.path.exists(UPLOAD_FOLDER + ID):
os.mkdir(UPLOAD_FOLDER + ID)
# get pdf file
photo = request.files['document']
photo.save(filename)
print("FILENAME: ", filename)
result = main.main(filename)
return(jsonify(result))
# GET
@app.route('/')
@app.route('/index')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run()