Created
August 11, 2017 17:15
-
-
Save smoofra/1b447977bde7e7bbc29fdf6895fd4453 to your computer and use it in GitHub Desktop.
export scuttle bookmarks into a form OwnCloud can import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import mysql.connector | |
import getpass | |
import cgi | |
import sys | |
mysqlpass = getpass.getpass("password for mysql: ", sys.stderr) | |
cnx = mysql.connector.connect(user='root', | |
password=mysqlpass, | |
host='127.0.0.1', | |
database='scuttle') | |
class Bookmark(object): | |
def __init__(self, title, description, address): | |
self.tags = [] | |
self.title = title | |
self.description = description | |
self.address = address | |
cursor = cnx.cursor() | |
cursor.execute("SELECT bTitle,bDescription,bAddress,bId FROM sc_bookmarks;") | |
bookmarks = dict((bId, Bookmark(bTitle,bDescription,bAddress)) | |
for (bTitle,bDescription,bAddress,bId) in cursor) | |
cursor.close() | |
cursor = cnx.cursor() | |
cursor.execute("SELECT bId,tag FROM sc_tags;") | |
for (bId,tag) in cursor: | |
if not tag.startswith('system:'): | |
bookmarks[bId].tags.append(tag) | |
cursor.close() | |
for bookmark in bookmarks.values(): | |
print u'<A DESCRIPTION="{description}" TAGS="{tags}" HREF="{url}">{title}</A>'.format( | |
tags=cgi.escape(','.join(bookmark.tags)), | |
url=bookmark.address, | |
title=cgi.escape(bookmark.title), | |
description=cgi.escape(bookmark.description)).encode('utf-8') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment