generated from EC-Nordbund/rollup-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
60 lines (44 loc) · 1.41 KB
/
build.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
const fs = require('fs')
const PATH = './data/'
const charMap = { '/': '\\/' }
function plz() {
if (!fs.existsSync(PATH)) {
fs.mkdirSync(PATH)
}
fs.readdirSync(PATH)
.filter((v) => v[0] !== '.')
.map((v) => PATH + v)
.forEach(fs.unlinkSync)
fetch(
'https://www.suche-postleitzahl.org/download_files/public/zuordnung_plz_ort.csv'
)
.then((v) => v.text())
.then((content) => {
const plzData = {}
const ortData = {}
content.split('\n').forEach((eintrag, id) => {
if (id === 0 || eintrag === '') {
return
}
const data = eintrag.split(',')
const plz = data[2]
const ort = data[1]
if (!plzData[plz]) {
plzData[plz] = []
}
plzData[plz].push(ort)
if (!ortData[ort.replace('/', '\\/')]) {
ortData[ort.replace('/', '\\/')] = []
}
ortData[ort.replace('/', '\\/')].push(plz)
})
const plzListe = Object.keys(plzData).sort()
plzListe.forEach((plz) => {
fs.writeFileSync(PATH + plz + '.json', JSON.stringify(plzData[plz]))
})
fs.writeFileSync(PATH + 'plz.json', JSON.stringify(plzListe.filter(v => ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].indexOf(v[0]) !== -1)))
fs.writeFileSync(PATH + 'plz.full.json', JSON.stringify(plzData))
fs.writeFileSync(PATH + 'ort.json', JSON.stringify(ortData))
})
}
plz()