Skip to content

Instantly share code, notes, and snippets.

@Bastian-Kuhn
Last active August 29, 2015 13:58
Show Gist options
  • Save Bastian-Kuhn/10169218 to your computer and use it in GitHub Desktop.
Save Bastian-Kuhn/10169218 to your computer and use it in GitHub Desktop.
Export Kindle Paperwhite vocables to csv
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3, sys
export_file = '/tmp/export.csv'
# State file to avoid duplicate exports
state_file = '/var/tmp/export-stats'
which_dicts = [ 'en', 'en-GB' ]
out = open(export_file, 'w')
try:
old = eval(file(state_file,"r").read())
except:
old = []
if len(sys.argv) > 1:
if sys.argv[1] == '-f':
old = []
count = 0
for row in sqlite3.connect("vocab.db").execute("SELECT * from WORDS"):
if row[3] in which_dicts:
word = row[1]
id_word = row[0]
if id_word in old:
continue
old.append(id_word)
count += 1
out.write( word + ";Translation\n")
file(state_file, "w").write(str(old))
print "Exported %d words to %s" % ( count, export_file )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment