-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
86 lines (67 loc) · 2.74 KB
/
app.py
File metadata and controls
86 lines (67 loc) · 2.74 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
83
84
85
86
import base64
import shutil
from flask import Flask, json
from flask import render_template
from flask.helpers import send_file
import os
import dotenv
from devcerts.install import ensure_certificates_are_installed
import subprocess
dotenv.load_dotenv()
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/taskpane.html")
def taskpane():
return render_template("taskpane.html")
@app.route("/commands.html")
def commands():
return render_template("commands.html")
@app.route("/assets/logo-filled.png")
def iconlogofilled():
return send_file("./static/assets/logo-filled.png",mimetype='image/png')
@app.route("/submit", methods=["POST"])
def submit():
print("\nReceived a submit POST request from the outlook addin")
data = request.get_json()
attachments = data['attachments']
manifestData = data['manifestData']
conversationId = manifestData.get("conversationId")
directory = os.path.join(r'c:/Users/mukes/Downloads/SmartDoc',conversationId)
# Remove the directory if it already exists
if os.path.exists(directory):
print(f"\nDirectory {directory} already exists. Recreating it. \n")
shutil.rmtree(directory)
#create a directory with the conversationId as the name
os.mkdir(directory)
for attachment in attachments:
name = attachment['name']
content = attachment['content']
# Decode the base64 content
file_content = base64.b64decode(content)
# Save the pdf files in the directory
file_path = os.path.join(directory, name)
with open(file_path, 'wb') as f:
print(f"Writing file {file_path}")
f.write(file_content)
# Save the mainfest file in the directory
with open(os.path.join(directory, "manifest.json"), "w") as f:
print("\nWriting manifest file.")
f.write(json.dumps(manifestData, indent=4))
# Running the classifile model
print("\nRunning the classifile model \n")
subprocess.run(["python", "./classifile.py", directory])
return "Attachments and Manifest uploaded successfully", 200
if __name__ == "__main__":
if os.environ.get("APP_MODE") == "DEV":
print("Running in DEV mode")
# Call the function to ensure certificates are installed and valid
ensure_certificates_are_installed()
# Assuming the ensure_certificates_are_installed function updates the default paths as needed
from devcerts.defaults import localhost_certificate_path, localhost_key_path
from flask import request
ssl_context = (localhost_certificate_path, localhost_key_path)
app.run(debug=True, ssl_context=ssl_context)
else:
app.run(debug=True)