Last active
September 27, 2021 05:43
-
-
Save djdembeck/bab05b0a8bec15ed68812cedfe4dbce7 to your computer and use it in GitHub Desktop.
Seeds audnexus with all current audible asins
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
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