Handle dashes in isbns

This commit is contained in:
Mouse Reeve
2020-10-30 12:43:02 -07:00
parent 9780879ce6
commit 3fc1f46897
2 changed files with 13 additions and 0 deletions

View File

@ -186,6 +186,7 @@ class Edition(Book):
def isbn_10_to_13(isbn_10):
''' convert an isbn 10 into an isbn 13 '''
isbn_10 = isbn_10.replace('-', '')
# drop the last character of the isbn 10 number (the original checkdigit)
converted = isbn_10[:9]
# add "978" to the front
@ -206,6 +207,8 @@ def isbn_13_to_10(isbn_13):
if isbn_13[:3] != '978':
return None
isbn_13 = isbn_13.replace('-', '')
# remove '978' and old checkdigit
converted = isbn_13[3:-1]
# calculate checkdigit