Kaynağa Gözat

improving book cover fetching

joel
Simon Bowie 2 yıl önce
ebeveyn
işleme
426e622ef3
3 değiştirilmiş dosya ile 28 ekleme ve 7 silme
  1. +14
    -4
      web/app/resources.py
  2. +12
    -2
      web/app/templates/book.html
  3. +2
    -1
      web/requirements.txt

+ 14
- 4
web/app/resources.py Dosyayı Görüntüle

@@ -10,6 +10,7 @@ from .models import Resource
from werkzeug.exceptions import abort
from . import db
from isbntools.app import *
import requests

# function to retrieve data about a single resource from the database
def get_resource(resource_id):
@@ -42,9 +43,18 @@ def get_filter_values(field):
return field_filter

def get_book_data(isbn):
try:
#try:
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
except:
pass
#except:
# pass

+ 12
- 2
web/app/templates/book.html Dosyayı Görüntüle

@@ -3,7 +3,7 @@
{% block content %}

{% 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 %}
<div class="row">
<div class="col">
@@ -42,7 +42,7 @@
</th>
<td>
{% for author in book['Authors'] %}
{{ author }},
{{ author }}
{% endfor %}
</td>
{% else %}
@@ -87,6 +87,16 @@
</td>
</tr>
{% endif %}
{% if book['desc'] %}
<tr>
<th>
Summary:
</th>
<td>
{{ book['desc'] }}
</td>
</tr>
{% endif %}
{% else %}
<!-- fields for books from database -->
{% if resource['name'] %}

+ 2
- 1
web/requirements.txt Dosyayı Görüntüle

@@ -5,4 +5,5 @@ flask-moment
gunicorn
pymysql
markdown
isbntools
isbntools
requests

Yükleniyor…
İptal
Kaydet