Skip to content

Instantly share code, notes, and snippets.

@stuartlynn
Last active September 25, 2020 18:03
Show Gist options
  • Save stuartlynn/ac55ea8a078a6853d0b3074fd773f9ed to your computer and use it in GitHub Desktop.
Save stuartlynn/ac55ea8a078a6853d0b3074fd773f9ed to your computer and use it in GitHub Desktop.
Example query
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