Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Script to convert Kindle clippings to Anki import file format
# -*- coding: utf-8 -*-
clippings = 'My Clippings.txt'
ankiFile = 'AnkiImport.txt'
def kindle_to_anki():
try:
clippingsFile = open(clippings, 'r')
except IOError, e:
print '*** file open error: ', e
anki_import = open(ankiFile, 'w')
kindle_notes = clippingsFile.readlines()
anki_import.writelines(['"%s"\t"%s"\n\n' % (kindle_notes[i].strip(), kindle_notes[i+3].strip())
for i in range(0, len(kindle_notes), 5)])
anki_import.close()
clippingsFile.close()
if __name__ == '__main__':
kindle_to_anki()
@billdockto

This comment has been minimized.

Copy link

commented Dec 14, 2011

I am kind of iliterate about this issue. Can you show me how to add it into my kindle.

@goghvanmr

This comment has been minimized.

Copy link
Owner Author

commented Dec 15, 2011

Hi billdockto,

This is just a script running on computer to convert the kindle clippings file into a anki import file format. I need this script because I use anki to manage the kindle highlights/notes. You can't add it into your kindle, on contrary you copy the "My Clippings.txt" file to your computer.

Tell me what you want it to be, maybe I can make some improvements:) For now, it's just a script for personal use:)

@billdockto

This comment has been minimized.

Copy link

commented Dec 16, 2011

It's a great idea. Can you show me step by step how can I do it ? How to run this script?

@goghvanmr

This comment has been minimized.

Copy link
Owner Author

commented Dec 20, 2011

To run this script, you have to have python installed in your pc. You put the script and the kindle clippings file (named "My Clippings.txt") under the same folder. After running the script (shell command: python kindle_anki.py), you will find a file named "AnkiImport.txt". That's the file to import into Anki.

@kchien

This comment has been minimized.

Copy link

commented Mar 1, 2012

This is awesome. I was going to write some script (either in CoffeeScript or Ruby) to screen scrape the notes that you can get on the web at https://kindle.amazon.com/. I'll probably write something similar to what you've written, just for fun though. :)

@michkles

This comment has been minimized.

Copy link

commented Apr 20, 2012

Hi! I followed your instructions but it failed to create Anki file. I put your script and My Clippings into python folder. Message from Command Line:
C:\Python32>python kindle_anki.py
File "kindle_anki.py", line 9
except IOError,e:
^
SyntaxError: invalid syntax

@goghvanmr

This comment has been minimized.

Copy link
Owner Author

commented Apr 21, 2012

Hello michkles,

I run this script under Python 2.7 and it works. I didn't test it under Python 3.2 . The Syntax of Python 3 is different from Python 2. I think that's why it didn't work under Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.