-
Notifications
You must be signed in to change notification settings - Fork 1
/
nodejs-example.js
54 lines (43 loc) · 1.51 KB
/
nodejs-example.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var http = require('http');
var url = require('url');
var receive = function(dataUrl, dataReady) {
var urlp = url.parse(dataUrl);
var service = http.createClient(urlp.port ? urlp.port : 80, urlp.hostname);
var req = service.request('GET', urlp.pathname + urlp.search,
{'host': urlp.hostname});
var data = null, status = null, finished = false;
req.on('response', function (res) {
var body = "";
status = res.statusCode;
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
data = JSON.parse(body);
if (!finished) {
finished = true;
dataReady(data);
}
});
});
req.end();
setTimeout(function() {
if (!finished) {
finished = true;
dataReady(null);
}
}, 2000);
};
console.log(process.cwd());
var ft = require(process.cwd() + '/lib/feed-tables.js');
receive("https://spreadsheets.google.com/feeds/cells/0AoooUkEfVrhldEpRekRVakVYWmJ2U2Z4SFBVZ0M1Nnc/od6/public/basic?alt=json",
function(data) {
if (data) {
var table = new ft.CellsFeed(data);
for (var r = 0; r < table.length; r++) {
var row = table.getRow(r);
console.log("name: " + row.name + ", street: " + row.street, " city: " + row.city + "\n");
}
} else
console.log("Timeout while fetching the Google Spreadsheet data.");
});