Check if we already have edition in our database before using openlibrary.
This commit is contained in:
parent
5148820fa3
commit
6d7f20caad
|
@ -4,6 +4,7 @@ import csv
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from fedireads import books_manager
|
from fedireads import books_manager
|
||||||
|
from fedireads.models import Edition
|
||||||
|
|
||||||
|
|
||||||
# Mapping goodreads -> fedireads shelf titles.
|
# Mapping goodreads -> fedireads shelf titles.
|
||||||
|
@ -49,22 +50,27 @@ class GoodreadsItem:
|
||||||
self.line = line
|
self.line = line
|
||||||
self.book = None
|
self.book = None
|
||||||
|
|
||||||
|
|
||||||
def resolve(self):
|
def resolve(self):
|
||||||
''' try various ways to lookup a book '''
|
''' try various ways to lookup a book '''
|
||||||
self.book = self.get_book_from_isbn()
|
self.book = (
|
||||||
if not self.book:
|
self.get_book_from_db_isbn() or
|
||||||
self.book = self.get_book_from_title_author()
|
self.get_book_from_isbn() or
|
||||||
|
self.get_book_from_title_author()
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_book_from_db_isbn(self):
|
||||||
|
''' see if we already know about the book '''
|
||||||
|
try:
|
||||||
|
return Edition.objects.get(isbn=self.isbn)
|
||||||
|
except Edition.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_book_from_isbn(self):
|
def get_book_from_isbn(self):
|
||||||
''' search by isbn '''
|
''' search by isbn '''
|
||||||
isbn = unquote_string(self.line['ISBN13'])
|
search_results = books_manager.search(self.isbn)
|
||||||
search_results = books_manager.search(isbn)
|
|
||||||
if search_results:
|
if search_results:
|
||||||
return books_manager.get_or_create_book(search_results[0].key)
|
return books_manager.get_or_create_book(search_results[0].key)
|
||||||
|
|
||||||
|
|
||||||
def get_book_from_title_author(self):
|
def get_book_from_title_author(self):
|
||||||
''' search by title and author '''
|
''' search by title and author '''
|
||||||
search_term = construct_search_term(
|
search_term = construct_search_term(
|
||||||
|
@ -75,6 +81,10 @@ class GoodreadsItem:
|
||||||
if search_results:
|
if search_results:
|
||||||
return books_manager.get_or_create_book(search_results[0].key)
|
return books_manager.get_or_create_book(search_results[0].key)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def isbn(self):
|
||||||
|
return unquote_string(self.line['ISBN13'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shelf(self):
|
def shelf(self):
|
||||||
''' the goodreads shelf field '''
|
''' the goodreads shelf field '''
|
||||||
|
|
Loading…
Reference in New Issue