-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchkivajson.js
executable file
·39 lines (31 loc) · 1.04 KB
/
fetchkivajson.js
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
#!/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");
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
// Setup a DOM environment to make jQuery happy
document = require('jsdom').jsdom(undefined);
window = document.defaultView;
jQuery = require('jquery');
// configure jQuery ajax
jQuery.support.cors = true;
jQuery.ajaxSettings.xhr = function() {
return new XMLHttpRequest();
};
/** 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({partners: data});
});