Skip to content

Instantly share code, notes, and snippets.

@petermanser
Created October 20, 2011 07:00
Show Gist options
  • Save petermanser/1300584 to your computer and use it in GitHub Desktop.
Save petermanser/1300584 to your computer and use it in GitHub Desktop.
Import Memonic Booksmarks (from the Memonic sqlite DB) to Zootool (API)
# Modify this configs with your credentials. See requirements.txt for required packages
DB_PATH = '/path/to/memonic.db'
ZT_USER = 'user'
ZT_PASS = 'pass'
ZT_API_KEY = '8e3f989331c3d687a75b96d9e5505008'
from pyzootool import controller
import sqlite3
zoocontrol = controller.ZooControl(apikey=ZT_API_KEY, username=ZT_USER, password=ZT_PASS)
try:
conn = sqlite3.connect(DB_PATH)
except Exception:
print 'Can\'t open sqlite DB (%s)' % DB_PATH
exit(1)
ci = conn.cursor()
cu = conn.cursor()
ct = conn.cursor()
ci.execute('select * from item')
count = 0
for item in ci:
title = item[2].encode('ascii', 'ignore')
# get the link
cu.execute('select * from itemdata where item = "%s"' % item[0])
for data in cu:
if data[1] == 'source':
url = data[2].encode('ascii', 'ignore')
# get the tags
ct.execute('select tag.title from tag inner join tag_item on tag.id = tag_item.tag where tag_item.item = "%s"' % item[0])
tags = ['memonic_import']
for tag in ct:
tags.append(tag[0].encode('ascii', 'ignore'))
print '%u: %s - %s, %s' % (count, title, url, ', '.join(tags))
try:
i = zoocontrol.item.add_item(url=url, title=title, tags=', '.join(tags))
except Exception:
print 'Wrong username/password, probably. :)'
exit(1)
count += 1
print '%u items imported from Memonic' % count
-e git+git@github.com:petermanser/pyzootool.git#egg=pyzootool-0.2-py2.7
httplib2==0.7.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment