Skip to content

Instantly share code, notes, and snippets.

@LukeMurphey
Created April 3, 2022 00:56
Show Gist options
  • Save LukeMurphey/ac3c5e3c5b74749ecb784c0d8e5b4abd to your computer and use it in GitHub Desktop.
Save LukeMurphey/ac3c5e3c5b74749ecb784c0d8e5b4abd to your computer and use it in GitHub Desktop.
Creates a CSV of your Kindle books.
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