-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchkivajson.js
More file actions
executable file
·39 lines (31 loc) · 1.07 KB
/
fetchkivajson.js
File metadata and controls
executable file
·39 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
/* This script fetches the list of kiva.org field partners from the kiva API
* and outputs them, in JSON format, to stdout.
*
* Use it like:
* $ node fetchkivajson.js > partners.json
*
* It does this by loading the jquery-kivasort plugin, and executing the same
* function that plugin uses in the browser. jquery and jsdom are required.
*/
var fs = require("fs");
// Setup a DOM environment to make jQuery happy
const { JSDOM, ResourceLoader } = require('jsdom');
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>',
{
url: "https://api.kivaws.org",
});
global.document = dom.window.document;
global.window = dom.window;
global.navigator = dom.window.navigator;
jQuery = require('jquery');
/** dummy object so we don't have to require datatables
* from node.js
*/
jQuery.fn= {dataTable: {ext: {}}};
// load jquery-kivasort plugin
var plugin = require('./kiva_sort.js');
// Fetch data and send it to stdout
plugin.fetchKivaPartners().done(function(data) {
console.log(JSON.stringify({partners: data}, null, 2));
});