Created
April 3, 2022 00:56
-
-
Save LukeMurphey/ac3c5e3c5b74749ecb784c0d8e5b4abd to your computer and use it in GitHub Desktop.
Creates a CSV of your Kindle books.
This file contains hidden or 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
import xml.dom.minidom | |
import csv | |
# Get the Kindle meta-data by: | |
# 1. Installing and running the Kindle app | |
# 2. Viewing the file in %appdata% at AppData\Local\Amazon\Kindle\Cache\KindleSyncMetadataCache.xml' | |
kindleMetaDataPath = 'KindleSyncMetadataCache.xml' | |
csvOutputPath = 'KindleBooks.csv' | |
def getText(nodelist): | |
rc = [] | |
for node in nodelist: | |
if node.nodeType == node.TEXT_NODE: | |
rc.append(node.data) | |
return ''.join(rc) | |
with open(csvOutputPath, 'w', newline='') as csvfile: | |
# Start the csv writer | |
csvwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL) | |
# Parse the document | |
metadata = xml.dom.minidom.parse(kindleMetaDataPath) | |
# Get the books | |
books = metadata.getElementsByTagName("meta_data") | |
for book in books: | |
title = book.getElementsByTagName("title") | |
csvwriter.writerow([getText(title[0].childNodes)]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment