-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathboundary-checker.js
64 lines (52 loc) · 1.54 KB
/
boundary-checker.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
const readline = require("readline");
const { promisify } = require("util");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question[promisify.custom] = (question) => {
return new Promise((resolve) => {
rl.question(question, resolve);
});
};
const boundaries = require("./src/config/boundaries.json");
const wikidata = require("./src/config/wikidata-gkz.json");
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
const newBoundaries = [];
const checkData = async () => {
await asyncForEach(boundaries, async (b) => {
const unitCode = b.unit_code;
let match = wikidata.find(
(w) => parseInt(w.gemeindekennzahl) === parseInt(unitCode)
);
while (!match) {
const answer = await promisify(rl.question)(
`${b.name}: GKZ not Found (Mapbox GKZ: ${unitCode}) | Please enter correct GKZ:`
);
match = wikidata.find(
(w) => parseInt(w.gemeindekennzahl) === parseInt(answer)
);
}
b.unit_code = "" + match.gemeindekennzahl;
b.name = match.gemeinde.replace(/ *\([^)]*\) */g, "");
b.wikidata = match.wikidata;
newBoundaries.push(b);
});
fs.writeFile(
"./src/config/boundaries_mapped.json",
JSON.stringify(newBoundaries),
"utf8",
() => {
console.log(
"New Data written to ./scr/config/boundaries_mapped.json. Goodbye!"
);
process.exit();
}
);
};
checkData();