-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (27 loc) · 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
from flask import Flask, render_template, redirect, jsonify, request
from application import PDFinder
app = Flask(__name__, template_folder='templates')
@app.route('/')
async def HomePage():
return render_template('index.html')
@app.route('/search/', methods=['POST', 'GET'])
async def SearchPDF():
if request.method == "POST":
query = request.json['query']
count = request.json['count']
if int(count) <= 0 or len(query) <= 2:
return jsonify({
"Sukses": False, "Message": "Jumlah harus lebih dari 0 dan pertanyaan minimal 3 karakter"
}), 400
else:
try:
PDF = await PDFinder.pdFINDER(pertanyaan=query, count=count)
return (PDF)
except (Exception) as e:
return jsonify({
"Sukses": False, "Message": f"{str(e)}"
}), 500
else:
return redirect('/')
if __name__=='__main__':
app.run(debug=True)