/
app.py
35 lines (25 loc) 路 845 Bytes
/
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
from flask import Flask, render_template, request, url_for
import requests
import json
import os
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
@app.route('/', methods=['GET'])
def booksearch():
# TODO: Extract query term from url
if request.method == 'GET':
search_term = request.args.get('q')
response = requests.get(f'https://www.googleapis.com/books/v1/volumes?q={search_term}')
books = response.json()
book_array = []
results = books['items']
# print(results)
for book in results:
book_array.append(book['volumeInfo']['imageLinks']['thumbnail'])
return render_template('index.html', book_array = book_array)
# @app.route('/<book_id>')
# def show_book():
# pass
if __name__ == '__main__':
app.run(debug=True)