| from werkzeug.exceptions import abort | from werkzeug.exceptions import abort | ||||
| from . import db | from . import db | ||||
| from isbntools.app import * | from isbntools.app import * | ||||
| import requests | |||||
| # function to retrieve data about a single resource from the database | # function to retrieve data about a single resource from the database | ||||
| def get_resource(resource_id): | def get_resource(resource_id): | ||||
| return field_filter | return field_filter | ||||
| def get_book_data(isbn): | def get_book_data(isbn): | ||||
| try: | |||||
| #try: | |||||
| book = meta(isbn) | book = meta(isbn) | ||||
| book.update(cover(isbn)) | |||||
| description = {'desc': desc(isbn)} | |||||
| book.update(description) | |||||
| # get highest-resolution book cover possible | |||||
| openl_url = 'https://covers.openlibrary.org/b/isbn/' + book['ISBN-13'] + '-L.jpg?default=false' | |||||
| request = requests.get(openl_url) | |||||
| if request.status_code != 200: | |||||
| book.update(cover(isbn)) | |||||
| else: | |||||
| book_cover = {'thumbnail': openl_url} | |||||
| book.update(book_cover) | |||||
| return book | return book | ||||
| except: | |||||
| pass | |||||
| #except: | |||||
| # pass |
| {% block content %} | {% block content %} | ||||
| {% if book['thumbnail'] %} | {% if book['thumbnail'] %} | ||||
| <img class="img-fluid mx-auto d-block" src={{ book['thumbnail'] }} alt="cover for {{ book['Title'] }}"> | |||||
| <img class="img-fluid mx-auto d-block py-3" src={{ book['thumbnail'] }} alt="cover for {{ book['Title'] }}"> | |||||
| {% else %} | {% else %} | ||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col"> | <div class="col"> | ||||
| </th> | </th> | ||||
| <td> | <td> | ||||
| {% for author in book['Authors'] %} | {% for author in book['Authors'] %} | ||||
| {{ author }}, | |||||
| {{ author }} | |||||
| {% endfor %} | {% endfor %} | ||||
| </td> | </td> | ||||
| {% else %} | {% else %} | ||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| {% endif %} | {% endif %} | ||||
| {% if book['desc'] %} | |||||
| <tr> | |||||
| <th> | |||||
| Summary: | |||||
| </th> | |||||
| <td> | |||||
| {{ book['desc'] }} | |||||
| </td> | |||||
| </tr> | |||||
| {% endif %} | |||||
| {% else %} | {% else %} | ||||
| <!-- fields for books from database --> | <!-- fields for books from database --> | ||||
| {% if resource['name'] %} | {% if resource['name'] %} |
| gunicorn | gunicorn | ||||
| pymysql | pymysql | ||||
| markdown | markdown | ||||
| isbntools | |||||
| isbntools | |||||
| requests |