pass isbn to add_by_googlebooks_id to address occasional missing isbns

pull/1/head
eric 2012-01-27 21:44:02 -05:00
parent c395405f7d
commit efa8da19ff
1 changed files with 10 additions and 9 deletions

View File

@ -105,7 +105,7 @@ def add_by_isbn_from_google(isbn, work=None):
return None return None
try: try:
return add_by_googlebooks_id(results['items'][0]['id'], work=work, results=results['items'][0]) return add_by_googlebooks_id(results['items'][0]['id'], work=work, results=results['items'][0], isbn=isbn)
except LookupFailure, e: except LookupFailure, e:
logger.exception("failed to add edition for %s", isbn) logger.exception("failed to add edition for %s", isbn)
except IntegrityError, e: except IntegrityError, e:
@ -127,10 +127,10 @@ def get_edition_by_id(type,value):
return None return None
def add_by_googlebooks_id(googlebooks_id, work=None, results=None): def add_by_googlebooks_id(googlebooks_id, work=None, results=None, isbn=None):
"""add a book to the UnglueIt database based on the GoogleBooks ID. The """add a book to the UnglueIt database based on the GoogleBooks ID. The
work parameter is optional, and if not supplied the edition will be work parameter is optional, and if not supplied the edition will be
associated with a stub work. associated with a stub work. isbn can be passed because sometimes passed data won't include it
""" """
# don't ping google again if we already know about the edition # don't ping google again if we already know about the edition
@ -155,7 +155,8 @@ def add_by_googlebooks_id(googlebooks_id, work=None, results=None):
logger.info("not connecting %s since it is %s instead of %s" % logger.info("not connecting %s since it is %s instead of %s" %
(googlebooks_id, language, work.language)) (googlebooks_id, language, work.language))
work = None work = None
isbn = None # isbn = None
if not isbn:
for i in d.get('industryIdentifiers', []): for i in d.get('industryIdentifiers', []):
if i['type'] == 'ISBN_10' and not isbn: if i['type'] == 'ISBN_10' and not isbn:
isbn = regluit.core.isbn.convert_10_to_13(i['identifier']) isbn = regluit.core.isbn.convert_10_to_13(i['identifier'])