Last active
June 28, 2022 05:35
-
-
Save david-bakin/255660af79c386460cdf0ee6a2a96291 to your computer and use it in GitHub Desktop.
Grab list of all Kindle books purchased from the currently logged in Amazon account - saves as a JSON file.
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
// Grab list of all kindle books purchased from the currently logged in | |
// Amazon account. Lets you save this list as a JSON file. | |
// The following data should be run in the console while viewing the page https://read.amazon.com/ | |
// Kindle booklist fetch derived from jkubecki/ExportKindle.js | |
// (https://gist.github.com/jkubecki/d61d3e953ed5c8379075b5ddd8a95f22) | |
// console.save grabbed from DevTools Snipppets | |
// (https://bgrins.github.io/devtools-snippets/#console-save) | |
// First define the console.save function - writes the console to a file | |
(function(console){ | |
console.save = function(data, filename){ | |
if(!data) { | |
console.error('Console.save: No data') | |
return; | |
} | |
if(!filename) filename = 'console.json' | |
if(typeof data === "object"){ | |
data = JSON.stringify(data, undefined, 4) | |
} | |
var blob = new Blob([data], {type: 'text/json'}), | |
e = document.createEvent('MouseEvents'), | |
a = document.createElement('a') | |
a.download = filename | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
} | |
})(console) | |
// Now open the database and grab the data | |
var db = openDatabase('K4W', '5', 'thedatabase', 2 * 1024 * 1024); // database version changed 2021-05 | |
getAmazonCsv = function() { | |
db.transaction(function(tx) { | |
tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) { | |
// Want to add a field to each element. Return value from | |
// tx.executeSql is readonly. So I convert it to an array (easy | |
// to iterate over) via the following roundabout technique. (I'm | |
// such a JavaScript novice...) | |
var as = Array.from(Object.values(JSON.parse(JSON.stringify(results.rows)))); | |
console.log(as.length); | |
for (i = 0; i < as.length; i++) { | |
as[i].purchaseDateInterpreted = new Date(as[i].purchaseDate).toLocaleDateString(); | |
} | |
console.save(as, 'amazon-kindle-booklist.json'); | |
}); | |
}); | |
}; | |
getAmazonCsv(); | |
db =''; |
Apparently read.amazon.com has changed and they're no longer using/updating the K4W database, so this code no longer works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://read.amazon.com
. Log in (if necessary). Let it refresh with your booklist.Fields for each book include ASIN, Title, Authors, and Purchase Date.