Skip to content

Instantly share code, notes, and snippets.

@djdembeck
Last active September 27, 2021 05:43
Show Gist options
  • Save djdembeck/bab05b0a8bec15ed68812cedfe4dbce7 to your computer and use it in GitHub Desktop.
Save djdembeck/bab05b0a8bec15ed68812cedfe4dbce7 to your computer and use it in GitHub Desktop.
Seeds audnexus with all current audible asins
const fetch = require('node-fetch');
const url = 'https://api.audible.com/1.0/catalog/products/?num_results=1'
const audnexus = 'https://api.audnex.us/books/'
function makeGetRequest(path) {
return new Promise(function (resolve, reject) {
fetch(path).then(
(response) => {
var result = response.json();
resolve(result);
},
(error) => {
reject(error);
}
);
});
}
async function getProduct() {
let pageCount = await makeGetRequest(url)
for (let i = 1; i < pageCount.total_results; i++) {
const pageRequest = async () => {
return makeGetRequest(url + `&page=${i}`).then((response) => {
return response
})
}
page = await pageRequest()
console.log(`${i}: ${page['products'][0]['asin']}`)
await makeGetRequest(audnexus + page['products'][0]['asin'])
await makeGetRequest(audnexus + page['products'][0]['asin'] + '/chapters')
}
}
getProduct()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment