-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
34 lines (26 loc) · 925 Bytes
/
server.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
from flask import Flask, render_template, request
app = Flask(__name__)
from library import Library
@app.route('/')
# @app.route('/?search=<search>')
# will want to add to sanitize searches (length of them etc.)
def search():
# url(?key=value)
s = request.args.get('search', '')
filename = 'new_lib_info.json'
lib = Library(filename, True)
# will want to get right from search in future
results = []
if s:
books = lib.search(s)
for book in books:
results.append(str(book))
if results == []:
results = -1
num_results = 0
if type(results) != int:
num_results = len(results)
return render_template('index.html', query=s, results=results, num_results=num_results)
# still have issues with effectiveness of search re libthing (see Herodotous search and CM in library.py)
if __name__ == '__main__':
app.run(debug=1)