Skip to content

Commit c6a8190

Browse files
authored
Add fixme and small changes to code
1 parent f56d461 commit c6a8190

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ name = "pypi"
55

66
[packages]
77
flask = "*"
8+
python-dotenv = "*"
89

910
[dev-packages]
1011

Pipfile.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixme

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
from flask import request, render_template, make_response
3+
4+
from server.webapp import flaskapp, cursor
5+
from server.models import Book
6+
7+
8+
@flaskapp.route('/')
9+
def index():
10+
name = request.args.get('name')
11+
author = request.args.get('author')
12+
read = bool(request.args.get('read'))
13+
14+
if name:
15+
cursor.execute(
16+
"SELECT * FROM books WHERE name LIKE :name", {'name': f"%{name}%"}
17+
)
18+
books = [Book(*row) for row in cursor]
19+
20+
elif author:
21+
cursor.execute(
22+
"SELECT * FROM books WHERE author LIKE :author", {'author': f"%{author}%"}
23+
)
24+
books = [Book(*row) for row in cursor]
25+
26+
else:
27+
cursor.execute("SELECT name, author, read FROM books")
28+
books = [Book(*row) for row in cursor]
29+
30+
return render_template('books.html', books=books)

server/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
sys.path.append('.')
34

@@ -29,7 +30,7 @@
2930
except Exception as err:
3031
print(f'[!] Error Occurred: {err}')
3132

32-
flaskapp.run('0.0.0.0', debug=True)
33+
flaskapp.run('0.0.0.0', debug=bool(os.environ.get('DEBUG', False)))
3334

3435
cursor.close()
3536
database.close()

server/routes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ def index():
1616
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
1717
)
1818
books = [Book(*row) for row in cursor]
19-
if len(books) == 0:
20-
return make_response(f"Search Result not found: {name}", 404)
2119

2220
elif author:
2321
cursor.execute(
2422
"SELECT * FROM books WHERE author LIKE '%" + author + "%'"
2523
)
2624
books = [Book(*row) for row in cursor]
27-
if len(books) == 0:
28-
return make_response(f"Search Result not found: {author}", 404)
2925

3026
else:
3127
cursor.execute("SELECT name, author, read FROM books")

0 commit comments

Comments
 (0)