forked from prabhakar267/WA-Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (35 loc) · 1.1 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
46
47
import os
import uuid
from flask import Flask, request, render_template, jsonify
from utils import get_parsed_file
app = Flask(__name__)
@app.route('/parse-file', methods=['POST'])
def parse_file():
file = request.files['0']
filename = str(uuid.uuid4())
tmp_filepath = os.path.join("conversations", filename)
file.save(tmp_filepath)
try:
parsed_items, persons_list = get_parsed_file(tmp_filepath)
response = {
"success": True,
"chat": parsed_items,
"users": persons_list
}
except Exception as e:
response = {
"success": False,
"error_message": str(e)
}
os.remove(tmp_filepath)
return jsonify(response), 200
@app.route('/', methods=['GET'])
def main():
return render_template("index.html")
@app.errorhandler(404)
def not_found(e):
message = "404 We couldn't find the page"
return render_template("index.html", error_message=message)
if __name__ == "__main__":
IS_PROD = os.environ.get("IS_PROD", False)
app.run(debug=not IS_PROD, host="0.0.0.0", threaded=True)