git ssb

0+

Dominic / weather



Tree: 5c787a5d6a07428ce30664e68a71eaa3278ea46b

Files: 5c787a5d6a07428ce30664e68a71eaa3278ea46b / index.js

678 bytesRaw
1
2var urls = require('./urls')
3var request = require('request')
4
5function 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
17var 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
27if(!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