-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 1.25 KB
/
index.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
'use strict'
const fs = require('fs');
const got = require('got');
const csv = require('csv');
fs.readFile('data/umschluesselungstabelle.csv', 'utf8', function(err, umschluesselungstabelle_csv) {
csv.parse(umschluesselungstabelle_csv, {columns: true, delimiter: ";"}, function(err, umschluesselungstabelle) {
const umschluesselung = umschluesselungstabelle.reduce((umschluesselung, item) => Object.assign(umschluesselung, { [item['stop_id']]: item['alte stop_id'] }), {});
fs.readFile('data/stops.txt', 'utf8', function(err, data) {
csv.parse(data, {columns: true, delimiter: ","}, function(err, stops) {
const processedStops = stops
.filter(stop => !stop.parent_station)
.map(stop => {
var stop_id = Number(umschluesselung[stop.stop_id] || stop.stop_id);
return {
stop_id : String(stop_id),
stop_code : String(stop.stop_id),
stop_name : stop.stop_name,
stop_lon : Number(stop.stop_lon),
stop_lat : Number(stop.stop_lat)
};
})
.filter(stop => (stop.stop_id >= 9000000 && stop.stop_id < 9500000));
csv.stringify(processedStops, {header: true, quotedString: true, columns: ["stop_id", "stop_name", "stop_lon", "stop_lat", "stop_code"]}, function(err, data){
process.stdout.write(data);
});
});
});
});
});