aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2017-06-12 23:45:46 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2017-06-12 23:45:46 +0200
commitc2e3aabfecef35dc007031c2f61b4bb0999aa14e (patch)
tree94fc026ac8f95bea381c6c8c8e65f92a68008b84 /src
parenttest tag for bookmarks (diff)
downloadnewspipe-c2e3aabfecef35dc007031c2f61b4bb0999aa14e.tar.gz
newspipe-c2e3aabfecef35dc007031c2f61b4bb0999aa14e.tar.bz2
newspipe-c2e3aabfecef35dc007031c2f61b4bb0999aa14e.zip
JSON export of bookmarks (compatible with Pinboard)
Diffstat (limited to 'src')
-rw-r--r--src/lib/data.py17
-rw-r--r--src/web/views/bookmark.py18
2 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/data.py b/src/lib/data.py
index 0ccea357..3d5ec495 100644
--- a/src/lib/data.py
+++ b/src/lib/data.py
@@ -190,3 +190,20 @@ def import_pinboard_json(user, json_content):
new_bookmark = bookmark_contr.create(**bookmark_attr)
nb_bookmarks += 1
return nb_bookmarks
+
+
+def export_bookmarks(user):
+ bookmark_contr = BookmarkController(user.id)
+ bookmarks = bookmark_contr.read()
+ export = []
+ for bookmark in bookmarks:
+ export.append({
+ 'href': bookmark.href,
+ 'description': bookmark.description,
+ 'title': bookmark.title,
+ 'shared': 'yes' if bookmark.shared else 'false',
+ 'toread': 'yes' if bookmark.to_read else 'false',
+ 'time': bookmark.time,
+ 'tags': ' '.join(bookmark.tags_proxy)
+ })
+ return jsonify(export)
diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py
index 18098d83..81189105 100644
--- a/src/web/views/bookmark.py
+++ b/src/web/views/bookmark.py
@@ -2,7 +2,7 @@
#-*- coding: utf-8 -*-
# Newspipe - A Web based news aggregator.
-# Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org
+# Copyright (C) 2010-2017 Cédric Bonhomme - https://www.cedricbonhomme.org
#
# For more information : https://github.com/newspipe/newspipe
#
@@ -31,7 +31,7 @@ import datetime
from werkzeug.exceptions import BadRequest
from flask import Blueprint, render_template, flash, \
- redirect, request, url_for
+ redirect, request, url_for, make_response
from flask_babel import gettext
from flask_login import login_required, current_user
from flask_paginate import Pagination, get_page_args
@@ -39,7 +39,7 @@ from sqlalchemy import desc
import conf
from lib.utils import redirect_url
-from lib.data import import_pinboard_json
+from lib.data import import_pinboard_json, export_bookmarks
from bootstrap import db
from web.forms import BookmarkForm
from web.controllers import BookmarkController, BookmarkTagController
@@ -229,6 +229,7 @@ def bookmarklet():
flash(gettext('Bookmark successfully created.'), 'success')
return redirect(url_for('bookmark.form', bookmark_id=new_bookmark.id))
+
@bookmark_bp.route('/import_pinboard', methods=['POST'])
@login_required
def import_pinboard():
@@ -242,3 +243,14 @@ def import_pinboard():
flash(gettext('Error when importing bookmarks.'), 'error')
return redirect(redirect_url())
+
+
+@bookmarks_bp.route('/export', methods=['GET'])
+@login_required
+def export():
+ bookmarks = export_bookmarks(current_user)
+ response = make_response(bookmarks)
+ response.mimetype = 'application/json'
+ response.headers["Content-Disposition"] \
+ = 'attachment; filename=newspipe_bookmarks_export.json'
+ return response
bgstack15