-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (55 loc) · 2.77 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, request, make_response, render_template, jsonify
from flask_restful import Resource, Api
from lib.Query import get, validation_test, empty_filter, make_it_ok
app = Flask(__name__, template_folder='templates')
api = Api(app)
# handle get request
class ReqHandler(Resource):
def get(self):
args = request.args
query = args['q']
query = query.lstrip(" ")
query = query.rstrip(" ")
is_valid = validation_test(query)
if is_valid:
query = make_it_ok(query)
ans = get(query)
res = empty_filter(ans)
if len(res) < 2:
index = render_template("index.html", qu=query,
p1=(res[0] if len(res) > 0 else ""),
p2="", p3="", p4="", p5="", p6="", p7="", p8="",
p9="", p10="")
elif res[0] == res[1]:
index = render_template("index.html", qu=query,
p1=(res[0] if len(res) > 0 else ""),
p2="", p3="", p4="", p5="", p6="", p7="", p8="",
p9="", p10="")
else:
index = render_template("index.html", qu=query,
p1=(res[0] if len(res) > 0 else ""),
p2=(res[1] if len(res) > 1 else ""),
p3=(res[2] if len(res) > 2 else ""),
p4=(res[3] if len(res) > 3 else ""),
p5=(res[4] if len(res) > 4 else ""),
p6=(res[5] if len(res) > 5 else ""),
p7=(res[6] if len(res) > 6 else ""),
p8=(res[7] if len(res) > 7 else ""),
p9=(res[8] if len(res) > 8 else ""),
p10=(res[9] if len(res) > 9 else ""))
return make_response(index)
else:
index = render_template("index.html",
p1="Your query is not acceptable", p2="Please enter persian characters"
, p3="", p4="", p5="", p6="", p7="", p8="", p9="", p10=""), 406
return make_response(index)
# return index.html
class IndexHandler(Resource):
def get(self):
index = render_template("index.html",
p1="", p2="", p3="", p4="", p5="", p6="", p7="", p8="", p9="", p10="")
return make_response(index)
api.add_resource(ReqHandler, '/search')
api.add_resource(IndexHandler, '/')
if __name__ == '__main__':
app.run(host="0.0.0.0")