def bookmark_save(): """Save a new bookmark.""" if 'user_id' not in session: abort(401) if request.form['title']: bookmark = { 'bookmark_id': request.form['id'] if request.form['id'] else None, 'rss': request.form['rss'], 'url': request.form['url'], 'title': request.form['title'], 'tags': map(lambda n: n.rstrip(","), request.form['tags'].split()) } feed_id = 0 seen = [] for tag in bookmark['tags']: if not re.search("^[a-zA-Z0-9_-]+$", tag): return render_template('bookmark/save.html', error="Invalid tag: %s" % tag, bookmark=bookmark) if tag in seen: return render_template('bookmark/save.html', error="Tag repeated: %s" % tag, bookmark=bookmark) seen.append(tag) try: bookmark_id = psutil.save_bookmark(g.db, session['user_id'], bookmark) except Exception, e: return render_template( 'bookmark/save.html', error= "Sorry, something went wrong whilst saving this bookmark. Please check that the feed URL is correct. (%s)" % e, bookmark=bookmark)
return render_template('bookmark/import.html') opml = request.files['file'].read() bookmarks = [] error = None try: bookmarks = psutil.parse_opml(opml) except Exception, e: return render_template("bookmark/import.html", error="Import failed, sorry! (%s)" % e) for bookmark in bookmarks: bookmark["imported"] = False try: psutil.save_bookmark(g.db, session["user_id"], bookmark) bookmark["imported"] = True except Exception, e: bookmark["exception"] = e bookmarks_imported = filter(lambda n: n["imported"], bookmarks) bookmarks_failed = filter(lambda n: not n["imported"], bookmarks) flash("Successfully imported %d bookmarks." % len(bookmarks_imported)) return render_template('bookmark/import_done.html', bookmarks_imported=bookmarks_imported, bookmarks_failed=bookmarks_failed) @app.route('/bookmark/export', methods=['GET', 'POST'])