-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate.js
46 lines (43 loc) · 1.16 KB
/
update.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
var fs = require('fs');
var httpism = require('httpism');
var csv = require('csv');
var dataUrl = 'https://github.com/opentraveldata/opentraveldata/raw/master/opentraveldata/optd_por_public.csv';
console.log('Fetching original data file');
httpism.get(dataUrl).then(response => {
var data = response.body;
console.log('Data retrieved');
var csvOptions = {
delimiter: '^',
relax: true,
columns: true
};
csv.parse(data, csvOptions, (err, airports) => {
if (err) {
console.log('----- Error ----')
console.log(err)
console.log('---- /Error ----')
}
else {
airports = airports.map(airport => {
return {
code: airport.iata_code,
countryCode: airport.country_code,
timezone: airport.timezone,
offset: {
gmt: parseInt(airport.gmt_offset),
dst: parseInt(airport.dst_offset)
}
}
}),
fs.writeFile('airports.json',
JSON.stringify(airports, null, 2),
(error) => {
if (error) {
console.log(error);
return;
}
console.log('airports.json updated')
});
}
});
});