forked from mirrors/bookwyrm
Fixes getting isbn for librarything imports
This commit is contained in:
parent
fb91c33682
commit
7f06ee3844
3 changed files with 10 additions and 5 deletions
|
@ -25,7 +25,7 @@ class Importer:
|
||||||
("title", ["title"]),
|
("title", ["title"]),
|
||||||
("authors", ["author", "authors", "primary author"]),
|
("authors", ["author", "authors", "primary author"]),
|
||||||
("isbn_10", ["isbn10", "isbn"]),
|
("isbn_10", ["isbn10", "isbn"]),
|
||||||
("isbn_13", ["isbn13", "isbn"]),
|
("isbn_13", ["isbn13", "isbn", "isbns"]),
|
||||||
("shelf", ["shelf", "exclusive shelf", "read status"]),
|
("shelf", ["shelf", "exclusive shelf", "read status"]),
|
||||||
("review_name", ["review name"]),
|
("review_name", ["review name"]),
|
||||||
("review_body", ["my review", "review"]),
|
("review_body", ["my review", "review"]),
|
||||||
|
|
|
@ -12,10 +12,12 @@ class LibrarythingImporter(Importer):
|
||||||
|
|
||||||
def normalize_row(self, entry, mappings): # pylint: disable=no-self-use
|
def normalize_row(self, entry, mappings): # pylint: disable=no-self-use
|
||||||
"""use the dataclass to create the formatted row of data"""
|
"""use the dataclass to create the formatted row of data"""
|
||||||
normalized = {k: entry.get(v) for k, v in mappings.items()}
|
remove_brackets = lambda v: re.sub(r"\[|\]", "", v) if v else None
|
||||||
for date_field in self.date_fields:
|
normalized = {
|
||||||
date = normalized[date_field]
|
k: remove_brackets(entry.get(v)) for k, v in mappings.items()
|
||||||
normalized[date_field] = re.sub(r"\[|\]", "", date)
|
}
|
||||||
|
isbn_13 = normalized["isbn_13"].split(', ')
|
||||||
|
normalized["isbn_13"] = isbn_13[1] if len(isbn_13) > 0 else None
|
||||||
return normalized
|
return normalized
|
||||||
|
|
||||||
def get_shelf(self, normalized_row):
|
def get_shelf(self, normalized_row):
|
||||||
|
|
|
@ -56,6 +56,9 @@ class LibrarythingImport(TestCase):
|
||||||
self.assertEqual(len(import_items), 3)
|
self.assertEqual(len(import_items), 3)
|
||||||
self.assertEqual(import_items[0].index, 0)
|
self.assertEqual(import_items[0].index, 0)
|
||||||
self.assertEqual(import_items[0].data["Book Id"], "5498194")
|
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].index, 1)
|
||||||
self.assertEqual(import_items[1].data["Book Id"], "5015319")
|
self.assertEqual(import_items[1].data["Book Id"], "5015319")
|
||||||
self.assertEqual(import_items[2].index, 2)
|
self.assertEqual(import_items[2].index, 2)
|
||||||
|
|
Loading…
Reference in a new issue