-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
97 lines (79 loc) · 2.46 KB
/
convert.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import got from "got";
import { writeFileSync } from "fs";
import sanitizeHtml from "sanitize-html";
const url = "https://geo.stadt-muenster.de/coronatests/data.php";
const loadData = async () => {
const response = await got.get(url);
// endpoint is a jsonp endpoint, strip away stuff that makes JSON.parse fail
let jsonStr = response.body;
jsonStr = jsonStr.slice(0, jsonStr.lastIndexOf(";"));
jsonStr = jsonStr.replace(/var\s.*\s=\s{/i, "{");
return JSON.parse(jsonStr);
};
// copied from original map https://geo.stadt-muenster.de/coronatests/
const anmeldType = {
A_TELMAIL: "Anmeldung per Mail oder telefonisch",
A_HOMEPAGE: "Anmeldung online",
X: "Anmeldung nicht erforderlich",
};
const artType = {
ARZT: "Arzt",
APO: "Apotheke",
T_ZENTER: "Testcenter",
};
const execute = async () => {
const json = await loadData();
const fc = { type: "FeatureCollection", features: [] };
// sanitize properties
for (const feature of json.features) {
let { name, str_name, hsnr, ...props } = feature.properties;
const address = `${sanitizeHtml(str_name)} ${sanitizeHtml(hsnr)}`.trim();
name = sanitizeHtml(name).trim();
const info = Object.entries(props)
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
.map(([key, value]) => {
if (key === "art") {
return artType[value];
}
if (key === "anmeld") {
return anmeldType[value];
}
const safeValue = sanitizeHtml(value).trim();
if (safeValue && key === "email") {
return `<a href="mailto:${safeValue}">${safeValue}</a>`;
}
if (safeValue && key === "homepage") {
return `<a target="_blank" rel="noopener" href="${safeValue}">${safeValue}</a>`;
}
if (safeValue && key === "tel1") {
return `<a href="tel:${safeValue}">${safeValue}</a>`;
}
if (safeValue && key === "besonders") {
return `Hinweis: ${safeValue}`;
}
return safeValue;
})
.filter((p) => p)
.join(", ");
const properties = {
name,
address,
info,
};
fc.features.push({
type: "Feature",
properties,
geometry: feature.geometry,
});
}
// sort by name
fc.features.sort(
({ properties: { name: nameA } }, { properties: { name: nameB } }) =>
nameA.localeCompare(nameB)
);
writeFileSync(
"./corona-testungen-muenster-extracted.json",
JSON.stringify(fc, undefined, 2)
);
};
execute();