Skip to content

Instantly share code, notes, and snippets.

@kmclaugh
Last active November 27, 2017 17:18
Show Gist options
  • Save kmclaugh/f7fc1541c77f975e469b9b3902be2c20 to your computer and use it in GitHub Desktop.
Save kmclaugh/f7fc1541c77f975e469b9b3902be2c20 to your computer and use it in GitHub Desktop.
Python script to convert clippings.io outputted Kindle Highlights into HTML files ready for evernote. Replace book_code, book_max_location with your book info and update all paths
#!/usr/bin/env python
import csv
from unidecode import unidecode
import os
import math
book_code = 'B06XKFP455'
kindle_highlights_url = 'https://kindle.amazon.com/your_highlights_and_notes/'+book_code
kindle_book_url = 'kindle://book?action=open&asin='+book_code + '&location=' ##40
book_max_location = 18456
book_location_padding = int(math.log10(book_max_location)) + 1
directory = '/Users/kevin/Desktop/notes/'
if os.path.exists(directory):
os.rmdir(directory)
os.makedirs(directory)
with open('/Users/kevin/Google Drive/notes.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
note_string = ''
#Content
if row['Content'] != '':
note_string = '<p>'+ row['Content'] + '</p>\n\n'
print(note_string)
##Source info
source = '<p>'+ row['Author'] + ', '
##Title link
source += '<em><a target="_blank" href="'+kindle_highlights_url+'" >'+ row['Title'] +'</a></em>, '
##Page
if row['Page'] != '':
source += 'Page: ' + row['Page'] + ', '
##Location link
source += '<a target="_blank" href="'+kindle_book_url+row["Location"]+'" >Kindle Location: '+row['Location']+'</a>'
source += '</p>\n\n'
note_string += source
##Notes
if row['Notes'] != '':
note_string += '<p>' + row['Notes'] + '</p>'
##Write to the file
filename = directory+ row['Location'].zfill(book_location_padding) +'.html' ##Use z-fill to zero pad so titles order correctly in Evernote
target = open(filename, 'w')
target.write(note_string)
target.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment