diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 5ad795cd..ecceb457 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -79,10 +79,17 @@ class Connector(AbstractConnector): cover_data = data.get('attachment') if not cover_data: return None - cover_url = cover_data[0].get('url') - response = requests.get(cover_url) + try: + cover_url = cover_data[0].get('url') + except IndexError: + return None + try: + response = requests.get(cover_url) + except ConnectionError: + return None + if not response.ok: - response.raise_for_status() + return None image_name = str(uuid4()) + '.' + cover_url.split('.')[-1] image_content = ContentFile(response.content) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 9b8afaa6..5c26ad45 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -177,10 +177,9 @@ class Connector(AbstractConnector): ''' load that author ''' if not re.match(r'^OL\d+A$', olkey): raise ValueError('Invalid OpenLibrary author ID') - try: - return models.Author.objects.get(openlibrary_key=olkey) - except models.Author.DoesNotExist: - pass + author = models.Author.objects.filter(openlibrary_key=olkey).first() + if author: + return author url = '%s/authors/%s.json' % (self.base_url, olkey) data = get_data(url) diff --git a/bookwyrm/goodreads_import.py b/bookwyrm/goodreads_import.py index fe5ac56e..d5c0ad42 100644 --- a/bookwyrm/goodreads_import.py +++ b/bookwyrm/goodreads_import.py @@ -20,7 +20,7 @@ def create_job(user, csv_file, include_reviews, privacy): ) for index, entry in enumerate(list(csv.DictReader(csv_file))[:MAX_ENTRIES]): if not all(x in entry for x in ('ISBN13', 'Title', 'Author')): - raise ValueError("Author, title, and isbn must be in data.") + raise ValueError('Author, title, and isbn must be in data.') ImportItem(job=job, index=index, data=entry).save() return job @@ -41,8 +41,11 @@ def import_data(job_id): for item in job.items.all(): try: item.resolve() - except HTTPError: - pass + except: + item.fail_reason = 'Error loading book' + item.save() + continue + if item.book: item.save() results.append(item) @@ -51,7 +54,7 @@ def import_data(job_id): outgoing.handle_imported_book( job.user, item, job.include_reviews, job.privacy) else: - item.fail_reason = "Could not find a match for book" + item.fail_reason = 'Could not find a match for book' item.save() finally: create_notification(job.user, 'IMPORT', related_import=job) diff --git a/bookwyrm/templates/import.html b/bookwyrm/templates/import.html index c3644812..8e3f5eb4 100644 --- a/bookwyrm/templates/import.html +++ b/bookwyrm/templates/import.html @@ -14,7 +14,8 @@
- Import started: {{ job.created_date | naturaltime }} + Import started: {{ job.created_date | naturaltime }} +
+ {% if task.successful %}- {% if task.ready %} - Import completed: {{ task.date_done | naturaltime }} - {% if task.failed %} -
- {{ task.info }} + Import completed: {{ task.date_done | naturaltime }} +
+ {% elif task.failed %} +- (Hit reload to update!) + (Hit reload to update!) +
{% endif %}@@ -59,9 +74,10 @@ {{ item.data|dict_key:'Author' }} | - {% if item.book %}✓ - {% elif item.fail_reason %} - {{ item.fail_reason }} + {% if item.book %} + + Imported + {% endif %} |
---|