path:
/ds100.js
1.74 KB | plain
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
const stations = require('db-stations')
const fs = require('fs');
const https = require('https');
var ds100list = {};
var ds100reverseList = {};
stations.full()
.on('data',function(station){
var stuff = [];
station.ril100Identifiers.forEach(element => {
stuff.push(element.rilIdentifier)
ds100list[element.rilIdentifier] = {
'ibnr': station.id
};
})
ds100reverseList[station.id] = stuff.join(', ');
fs.writeFile("data/db/stations/"+station.id+".json", JSON.stringify({
'id': station.id,
'name': station.name,
'latitude': station.location.latitude,
'longitude': station.location.longitude,
'category': station.category,
'hasDBLounge': station.hasDBLounge,
'hasSteplessAccess': station.hasSteplessAccess,
'hasPublicFacilities': station.hasPublicFacilities
}), () => {});
})
.on('end',function(){
https.get("https://api.railway-stations.org/de/stations", (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
json.forEach(element => {
if(ds100list[element["DS100"]]){
ds100list[element["DS100"]]["RailwayMapId"] = element["id"]
}
});
fs.writeFile("data/db/ds100.json", JSON.stringify(ds100list), () => {});
fs.writeFile("data/db/ds100reverse.json", JSON.stringify(ds100reverseList), () => {});
} catch (error) {
console.error(error.message);
};
});
}).on("error", (error) => {
console.error(error.message);
});
});