Style fixes suggested by pylint.
This commit is contained in:
parent
894f76f843
commit
fba78d7a0e
26 changed files with 37 additions and 73 deletions
|
@ -33,34 +33,29 @@ class AbstractConnector(ABC):
|
|||
def search(self, query):
|
||||
''' free text search '''
|
||||
# return list of search result objs
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def get_or_create_book(self, book_id):
|
||||
''' request and format a book given an identifier '''
|
||||
# return book model obj
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def expand_book_data(self, book):
|
||||
''' get more info on a book '''
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def get_or_create_author(self, book_id):
|
||||
''' request and format a book given an identifier '''
|
||||
# return book model obj
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def update_book(self, book_obj):
|
||||
''' sync a book with the canonical remote copy '''
|
||||
# return book model obj
|
||||
pass
|
||||
|
||||
|
||||
def update_from_mappings(obj, data, mappings):
|
||||
|
@ -96,7 +91,7 @@ def get_date(date_string):
|
|||
return None
|
||||
|
||||
|
||||
class SearchResult(object):
|
||||
class SearchResult:
|
||||
''' standardized search result object '''
|
||||
def __init__(self, title, key, author, year, raw_data):
|
||||
self.title = title
|
||||
|
@ -108,4 +103,3 @@ class SearchResult(object):
|
|||
def __repr__(self):
|
||||
return "<SearchResult key={!r} title={!r} author={!r}>".format(
|
||||
self.key, self.title, self.author)
|
||||
|
||||
|
|
|
@ -9,11 +9,6 @@ from .abstract_connector import update_from_mappings, get_date
|
|||
|
||||
|
||||
class Connector(AbstractConnector):
|
||||
''' instantiate a connector '''
|
||||
def __init__(self, identifier):
|
||||
super().__init__(identifier)
|
||||
|
||||
|
||||
def search(self, query):
|
||||
''' right now you can't search fedireads, but... '''
|
||||
resp = requests.get(
|
||||
|
@ -80,7 +75,7 @@ class Connector(AbstractConnector):
|
|||
author_id = author_id.split('/')[-1]
|
||||
book.authors.add(self.get_or_create_author(author_id))
|
||||
|
||||
if book.sync_cover and data.get('covers') and len(data['covers']):
|
||||
if book.sync_cover and data.get('covers') and data['covers']:
|
||||
book.cover.save(*get_cover(data['covers'][0]), save=True)
|
||||
|
||||
return book
|
||||
|
@ -119,4 +114,3 @@ def get_cover(cover_url):
|
|||
response.raise_for_status()
|
||||
image_content = ContentFile(response.content)
|
||||
return [image_name, image_content]
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
''' openlibrary data connector '''
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db import transaction
|
||||
import re
|
||||
import requests
|
||||
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db import transaction
|
||||
|
||||
from fedireads import models
|
||||
from .abstract_connector import AbstractConnector, SearchResult
|
||||
from .abstract_connector import update_from_mappings, get_date
|
||||
|
@ -247,7 +248,7 @@ def get_languages(language_blob):
|
|||
|
||||
def pick_default_edition(options):
|
||||
''' favor physical copies with covers in english '''
|
||||
if not len(options):
|
||||
if not options:
|
||||
return None
|
||||
if len(options) == 1:
|
||||
return options[0]
|
||||
|
@ -261,5 +262,3 @@ def pick_default_edition(options):
|
|||
options = [e for e in options if e.get('isbn_13')] or options
|
||||
options = [e for e in options if e.get('ocaid')] or options
|
||||
return options[0]
|
||||
|
||||
|
||||
|
|
|
@ -38,4 +38,3 @@ class Connector(AbstractConnector):
|
|||
|
||||
def update_book(self, book_obj):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue