Fixes getting isbn for librarything imports

This commit is contained in:
Mouse Reeve 2021-11-13 12:46:27 -08:00
parent fb91c33682
commit 7f06ee3844
3 changed files with 10 additions and 5 deletions

View file

@ -25,7 +25,7 @@ class Importer:
("title", ["title"]),
("authors", ["author", "authors", "primary author"]),
("isbn_10", ["isbn10", "isbn"]),
("isbn_13", ["isbn13", "isbn"]),
("isbn_13", ["isbn13", "isbn", "isbns"]),
("shelf", ["shelf", "exclusive shelf", "read status"]),
("review_name", ["review name"]),
("review_body", ["my review", "review"]),

View file

@ -12,10 +12,12 @@ class LibrarythingImporter(Importer):
def normalize_row(self, entry, mappings): # pylint: disable=no-self-use
"""use the dataclass to create the formatted row of data"""
normalized = {k: entry.get(v) for k, v in mappings.items()}
for date_field in self.date_fields:
date = normalized[date_field]
normalized[date_field] = re.sub(r"\[|\]", "", date)
remove_brackets = lambda v: re.sub(r"\[|\]", "", v) if v else None
normalized = {
k: remove_brackets(entry.get(v)) for k, v in mappings.items()
}
isbn_13 = normalized["isbn_13"].split(', ')
normalized["isbn_13"] = isbn_13[1] if len(isbn_13) > 0 else None
return normalized
def get_shelf(self, normalized_row):

View file

@ -56,6 +56,9 @@ class LibrarythingImport(TestCase):
self.assertEqual(len(import_items), 3)
self.assertEqual(import_items[0].index, 0)
self.assertEqual(import_items[0].data["Book Id"], "5498194")
self.assertEqual(import_items[0].normalized_data["isbn_13"], "9782070291342")
self.assertEqual(import_items[0].normalized_data["isbn_10"], "2070291340")
self.assertEqual(import_items[1].index, 1)
self.assertEqual(import_items[1].data["Book Id"], "5015319")
self.assertEqual(import_items[2].index, 2)