Created
August 7, 2018 09:52
-
-
Save goghvanmr/f8591635869b4cbeda7380c21854db16 to your computer and use it in GitHub Desktop.
Export Kindle Notes from Kindle exported html file to Anki imported compatible csv file
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
# -*- coding: utf-8 -*- | |
from bs4 import BeautifulSoup | |
import unicodecsv as csv | |
def export_notes_from(htmlFileName, csvFileName): | |
with open (htmlFileName) as html: | |
soup = BeautifulSoup(html, 'html.parser') | |
notes = [note.contents[0].strip('\r\n\ ') for note in soup.find_all('div', {'class', 'noteText'})] | |
title = soup.find(class_='bookTitle').contents[0].strip('\r\n\ ') | |
authors = soup.find(class_='authors').contents[0].strip('\r\n\ ') | |
titleAndAuthors = title + '\n' + authors | |
with open(csvFileName, 'wb') as csvFile: | |
writer = csv.writer(csvFile, delimiter=',') | |
for note in notes: | |
writer.writerow([note, titleAndAuthors]) | |
htmlFile = 'notes.html' | |
ankiCSV = 'exported.csv' | |
if __name__ == '__main__': | |
export_notes_from(htmlFile, ankiCSV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment