-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate-json.js
73 lines (64 loc) · 3.97 KB
/
update-json.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const async = require('async')
const fs = require('fs')
const iconv = require('iconv-lite')
const merge = require('deepmerge')
const path = require('path')
const progressBar = require('node-progress-3')
const request = require('request')
let URLArray = [
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=420709.4036816098,4569099.802774696,430493.34330211236,4578883.7423951980',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=420709.4036816098,4578883.742395198,430493.34330211236,4588667.68201570',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=420709.4036816098,4588667.6820157,430493.34330211236,4598451.6216362030',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=430493.3433021121,4569099.802774696,440277.28292261466,4578883.7423951980',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=430493.3433021121,4578883.742395198,440277.28292261466,4588667.68201570',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=430493.3433021121,4588667.6820157,440277.28292261466,4598451.6216362030',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=410925.4640611075,4559315.863154193,430493.3433021126,4578883.7423951990',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=410925.4640611075,4578883.742395198,430493.3433021126,4598451.62163620350',
'https://w33.bcn.cat/planolBCN/mapserv.ashx?ccapa=K021&lang=CA&layer=EQUIPS_GUIA&VERSION=1.0.0?&th=4&request=GetFeature&TYPENAME=K021&SERVICE=WFS&maxfeatures=2000&OUTPUTFORMAT=application/json&&bbox=430493.3433021121,4578883.742395198,450061.2225431172,4598451.62163620350'
]
let JSONArray = []
let JSONOutput = 'src/data/barcelona-bicycle-anchors.json'
let JSONMerge
let bar = new progressBar({
complete: '=',
format: 'Downloading JSON (:current/' + URLArray.length + ') [:bar] :percent',
incomplete: ' ',
total: URLArray.length,
width: 20
})
let q = async.queue(function (task, done) {
request.get({
url: task.url,
json: true,
encoding: null
}, function(err, res, body) {
if (err) return done(err)
if (res.statusCode != 200) return done(res.statusCode)
body = iconv.decode(body, 'UTF-16')
JSONArray.push(JSON.parse(body))
bar.tick()
done()
})
}, 5)
q.drain = function() {
console.log('Merging JSON ...')
JSONMerge = merge.all(JSONArray)
console.log('\033[1;32mAll JSON merged successfully!\033[0m')
fs.writeFile(JSONOutput, JSON.stringify(JSONMerge, null, 4), function(err) {
if (err) {
console.log(err)
} else {
console.log('\nJSON saved to "' + JSONOutput + '"')
}
})
}
async.eachOf(URLArray, function(url, index, callback) {
q.push({
url: url,
index: index
})
})
bar.onComplete = function() {
console.log('\n\033[1;32mDownload complete.\033[0m\n')
// process.exit()
}