Last active
September 25, 2020 18:03
-
-
Save stuartlynn/ac55ea8a078a6853d0b3074fd773f9ed to your computer and use it in GitHub Desktop.
Example query
This file contains 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 ckan = require('ckan'); | |
var client = new ckan.Client('https://data.humdata.org/'); | |
client.requestType = 'GET'; | |
function getPages() { | |
return new Promise((resolve, reject) => { | |
const getPage = (offset, page, datasetsToDate) => { | |
console.log( | |
'requesting offset ', | |
offset, | |
'page', | |
page, | |
' have got ', | |
datasetsToDate.length, | |
' datasets', | |
); | |
client.action( | |
'datastore_search', | |
{ | |
resource_id: '_table_metadata', | |
offset: offset, | |
}, | |
(err, out) => { | |
console.log(out); | |
console.log(out.result.records.length); | |
if (err || !out.success || out.result.records.length === 0) { | |
resolve(datasetsToDate); | |
} else { | |
getPage(offset + 100, page + 1, [ | |
...datasetsToDate, | |
...out.result.records, | |
]); | |
} | |
}, | |
); | |
}; | |
getPage(0, 0, []); | |
}); | |
} | |
getPages() | |
.then((result) => { | |
console.log(result); | |
console.log('have ', result.length, ' datasets '); | |
return result; | |
}) | |
.then((outputResults) => { | |
outputResults.forEach((r) => console.log(r.name)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment