www.fgks.org   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Don't write non-ISBN 10 ASINs to the isbn_10 field of a record
Browse files Browse the repository at this point in the history
For books, Amazon usually returns ISBN 10s as its ASIN, but sometimes,
particularly in the case of ebooks, they may be numbers starting with
`B`, rather than ISBN 10s. This commit keeps the non-ISBN 10 ASIN in the
`source_records: ["amazon:asin"]` line, but prevents them from entering
the `isbn_10` field.

It also prevents `isbn_10` and `isbn_13` from having truthy `[None]`
values.
  • Loading branch information
scottbarnes committed Mar 13, 2024
1 parent 545cf04 commit 14e3ef7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions openlibrary/core/vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,16 @@ def serialize(product: Any) -> dict:
logger.exception(f"serialize({product})")
publish_date = None

asin_is_isbn10 = not product.asin.startswith("B")
isbn_13 = isbn_10_to_isbn_13(product.asin) if asin_is_isbn10 else None

book = {
'url': "https://www.amazon.com/dp/{}/?tag={}".format(
product.asin, h.affiliate_id('amazon')
),
'source_records': ['amazon:%s' % product.asin],
'isbn_10': [product.asin],
'isbn_13': [isbn_10_to_isbn_13(product.asin)],
'isbn_10': [product.asin] if asin_is_isbn10 else [],
'isbn_13': [isbn_13] if isbn_13 else [],
'price': price and price.display_amount,
'price_amt': price and price.amount and int(100 * price.amount),
'title': (
Expand Down

0 comments on commit 14e3ef7

Please sign in to comment.