Browse Source

curated homepage

joel
Simon Bowie 1 year ago
parent
commit
aa1c505b6f
1 changed files with 22 additions and 9 deletions
  1. +22
    -9
      web/app/resources.py

+ 22
- 9
web/app/resources.py View File

from isbntools.app import * from isbntools.app import *
import requests import requests
import re import re
from sqlalchemy.sql import func


# 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):
resource.__dict__.update(book_data) resource.__dict__.update(book_data)
return resource return resource


# function to retrieve data about a curated list of resources
def get_curated_resources(resource_ids):
resources = Resource.query.filter(Resource.id.in_(resource_ids)).order_by(func.random()).all()
# append relationships to each resource
append_relationships_multiple(resources)
return resources

# function to delete a single resource # function to delete a single resource
def delete_resource(resource_id): def delete_resource(resource_id):
deletion = Resource.query.get(resource_id) deletion = Resource.query.get(resource_id)
book = meta(isbn) book = meta(isbn)
description = {'desc': desc(isbn)} description = {'desc': desc(isbn)}
book.update(description) 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)
#book = get_book_cover(book)
return book return book
except: except:
pass
pass

# function to get book cover data
def get_book_cover(book):
# 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

Loading…
Cancel
Save