Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Amazon Kindle Export
// The following data should be run in the console while viewing the page https://read.amazon.com/
// It will export a CSV file called "download" which can (and should) be renamed with a .csv extension
var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024);
getAmazonCsv = function() {
// Set header for CSV export line - change this if you change the fields used
var csvData = "ASIN,Title,Authors,PurchaseDate\n";
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) {
var len = results.rows.length;
for (i = 1; i < len; i++) {
// Get the data
var asin = results.rows.item(i).asin;
var title = results.rows.item(i).title;
var authors = JSON.parse(results.rows.item(i).authors);
var purchaseDate = new Date(results.rows.item(i).purchaseDate).toLocaleDateString();
// Remove double quotes from titles to not interfere with CSV double-quotes
title = title.replace(/"/g, '');
// Concatenate the authors list - uncomment the next line to get all authors separated by ";"
// var authorList = authors.join(';');
// OR Take only first author - comment the next line if you uncommented the previous one
var authorList = authors[0];
// Write out the CSV line
csvData += '"' + asin + '","' + title + '","' + authorList + '","' + purchaseDate + '"\n'
}
// "Export" the data
window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(csvData);
console.log("Sample Row:");
console.log(results.rows.item(1));
});
});
};
getAmazonCsv();
@micheledicosmo

This comment has been minimized.

Copy link

micheledicosmo commented Feb 12, 2017

Cool and Smart!

@morja

This comment has been minimized.

Copy link

morja commented May 2, 2018

Great! Thanks a lot.

@Coriakin

This comment has been minimized.

Copy link

Coriakin commented Jul 27, 2018

This is splendid work, and exactly what I was looking for, cheers!

@heathkat

This comment has been minimized.

Copy link

heathkat commented Dec 5, 2018

What a simple yet powerful and elegant solution to an ongoing need that Amazon refuses to address. Thank you!

@ibuddy66

This comment has been minimized.

Copy link

ibuddy66 commented Mar 30, 2019

Provides the following errors now:
VM37:1 Uncaught DOMException: Failed to execute 'openDatabase' on 'Window': unable to open database, version mismatch, '2' does not match the currentVersion of '3'
at :1:10

@thebenwaters

This comment has been minimized.

Copy link

thebenwaters commented Apr 12, 2019

Amazing you saved me much time and disk space over using calibre :)

@ravivyas84

This comment has been minimized.

Copy link

ravivyas84 commented May 10, 2019

Provides the following errors now:
VM37:1 Uncaught DOMException: Failed to execute 'openDatabase' on 'Window': unable to open database, version mismatch, '2' does not match the currentVersion of '3'
at :1:10

Change

var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024);

to

var db = openDatabase('K4W', '3', 'thedatabase', 1024 * 1024);

and it works

@Soderborg-Bonnie

This comment has been minimized.

Copy link

Soderborg-Bonnie commented May 17, 2019

Thank you! What a huge time saver!

@compwron

This comment has been minimized.

Copy link

compwron commented Dec 21, 2019

It still works, with the minor change of replacing var db = openDatabase('K4W', '2', 'thedatabase', 1024 * 1024); '2' with '3' :)
Thank you so much :)

@ianmack-byte

This comment has been minimized.

Copy link

ianmack-byte commented Jan 11, 2020

Great Script, been looking for something like this for ages

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.