From b9d13f6489f8948b247ed045a2fd04a3c6ee9396 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Mon, 2 Mar 2020 13:16:23 +0100 Subject: fixed issue with the function to import bookmarks from a JSON file. --- newspipe/lib/data.py | 13 ++++++++++--- newspipe/web/templates/layout.html | 1 - newspipe/web/views/bookmark.py | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/newspipe/lib/data.py b/newspipe/lib/data.py index 571aaf63..7c6beff9 100644 --- a/newspipe/lib/data.py +++ b/newspipe/lib/data.py @@ -204,13 +204,20 @@ def import_pinboard_json(user, json_content): for tag in bookmark["tags"].split(" "): new_tag = BookmarkTag(text=tag.strip(), user_id=user.id) tags.append(new_tag) + try: + # Pinboard format + description = bookmark["extended"] + time = datetime.datetime.strptime(bookmark["time"], "%Y-%m-%dT%H:%M:%SZ") + except Exception: + description = bookmark["description"] + time = datetime.datetime.strptime(bookmark["time"], "%Y-%m-%dT%H:%M:%S") bookmark_attr = { "href": bookmark["href"], - "description": bookmark["extended"], - "title": bookmark["description"], + "description": description, + "title": description, "shared": [bookmark["shared"] == "yes" and True or False][0], "to_read": [bookmark["toread"] == "yes" and True or False][0], - "time": datetime.datetime.strptime(bookmark["time"], "%Y-%m-%dT%H:%M:%SZ"), + "time": time, "tags": tags, } new_bookmark = bookmark_contr.create(**bookmark_attr) diff --git a/newspipe/web/templates/layout.html b/newspipe/web/templates/layout.html index d83333a3..1453c3fd 100644 --- a/newspipe/web/templates/layout.html +++ b/newspipe/web/templates/layout.html @@ -94,7 +94,6 @@  {{ _('Profile') }}  {{ _('Your data') }} {{ _('About') }} - {{ _('All') }} {% if current_user.is_admin %} {{ _('Dashboard') }} diff --git a/newspipe/web/views/bookmark.py b/newspipe/web/views/bookmark.py index c46409e4..6b370658 100644 --- a/newspipe/web/views/bookmark.py +++ b/newspipe/web/views/bookmark.py @@ -263,6 +263,7 @@ def bookmarklet(): def import_pinboard(): bookmarks = request.files.get("jsonfile", None) if bookmarks: + nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) try: nb_bookmarks = import_pinboard_json(current_user, bookmarks.read()) flash( @@ -272,7 +273,7 @@ def import_pinboard(): ), "success", ) - except Exception as e: + except Exception: flash(gettext("Error when importing bookmarks."), "error") return redirect(redirect_url()) -- cgit