Files: 5eb47c64b87215ab4daa1b2e534ce2b82ac0a95f / index.js
678 bytesRaw
1 | |
2 | var urls = require('./urls') |
3 | var request = require('request') |
4 | |
5 | function clean (data) { |
6 | if('string' === typeof data) return data |
7 | if(Array.isArray(data)) |
8 | return data.map(clean) |
9 | var o = {} |
10 | for(var k in data) { |
11 | if(!/^_/.test(k)) |
12 | o[k] = clean(data[k]) |
13 | } |
14 | return o |
15 | } |
16 | |
17 | var retrive = module.exports = function (name, cb) { |
18 | var url = urls[name] |
19 | console.error('GET', url) |
20 | request({url: url, json: true}, function (err, response, json) { |
21 | if(err) return cb(err) |
22 | json.name = name |
23 | cb(null, clean(json)) |
24 | }) |
25 | } |
26 | |
27 | if(!module.parent) { |
28 | retrive(process.argv[2] || 'auckland', function (err, json) { |
29 | if(err) throw err |
30 | console.log(json) |
31 | }) |
32 | } |
33 | |
34 |
Built with git-ssb-web