diff --git a/bookwyrm/importers/importer.py b/bookwyrm/importers/importer.py index 71f02231..db13b652 100644 --- a/bookwyrm/importers/importer.py +++ b/bookwyrm/importers/importer.py @@ -20,20 +20,20 @@ class Importer: encoding = "UTF-8" # these are from Goodreads - row_mappings_guesses = { - "id": ["id", "book id"], - "title": ["title"], - "authors": ["author", "authors", "primary author"], - "isbn_13": ["isbn13", "isbn"], - "isbn_10": ["isbn10", "isbn"], - "shelf": ["shelf", "exclusive shelf", "read status"], - "review_name": ["review name"], - "review_body": ["my review", "review"], - "rating": ["my rating", "rating", "star rating"], - "date_added": ["date added", "entry date", "added"], - "date_started": ["date started", "started"], - "date_finished": ["date finished", "last date read", "date read", "finished"], - } + row_mappings_guesses = [ + ("id", ["id", "book id"]), + ("title", ["title"]), + ("authors", ["author", "authors", "primary author"]), + ("isbn_10", ["isbn10", "isbn"]), + ("isbn_13", ["isbn13", "isbn"]), + ("shelf", ["shelf", "exclusive shelf", "read status"]), + ("review_name", ["review name"]), + ("review_body", ["my review", "review"]), + ("rating", ["my rating", "rating", "star rating"]), + ("date_added", ["date added", "entry date", "added"]), + ("date_started", ["date started", "started"]), + ("date_finished", ["date finished", "last date read", "date read", "finished"]), + ] date_fields = ["date_added", "date_started", "date_finished"] shelf_mapping_guesses = { "to-read": ["to-read"], @@ -60,7 +60,7 @@ class Importer: def create_row_mappings(self, headers): """guess what the headers mean""" mappings = {} - for (key, guesses) in self.row_mappings_guesses.items(): + for (key, guesses) in self.row_mappings_guesses: value = [h for h in headers if h.lower() in guesses] value = value[0] if len(value) else None if value: diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 6b8f0b46..18565017 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -12,6 +12,8 @@ from .fields import PrivacyLevels def unquote_string(text): """resolve csv quote weirdness""" + if not text: + return None match = re.match(r'="([^"]*)"', text) if match: return match.group(1) @@ -122,7 +124,7 @@ class ImportItem(models.Model): @property def isbn(self): """pulls out the isbn13 field from the csv line data""" - return unquote_string(self.normalized_data["isbn_13"]) + return unquote_string(self.normalized_data["isbn_13"]) or unquote_string(self.normalized_data["isbn_10"]) @property def shelf(self): diff --git a/bookwyrm/templates/import/import_status.html b/bookwyrm/templates/import/import_status.html index f5f590e1..8208a2fa 100644 --- a/bookwyrm/templates/import/import_status.html +++ b/bookwyrm/templates/import/import_status.html @@ -125,7 +125,7 @@ {{ item.normalized_data.title }}