-
Notifications
You must be signed in to change notification settings - Fork 3
/
split_address_map.mjs
30 lines (21 loc) · 959 Bytes
/
split_address_map.mjs
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
import { readdir, readFile, writeFile } from 'fs/promises'
import { basename } from 'path'
const dateDir = 'docs/data/date'
const files = await readdir(dateDir)
const addressMap = JSON.parse(await readFile('docs/addressMap.json', { encoding: 'utf-8'}))
for (const dateJson of files) {
const dataOfDate = JSON.parse(await readFile(dateDir + '/' + dateJson, { encoding: 'utf-8' }))
for (const district in dataOfDate) {
const dataOfDistrict = dataOfDate[district]
if (dataOfDistrict.addressWithLocation) continue
const addressWithLocation = []
for (const address of dataOfDistrict.addresses) {
const fullAddress = district + address
const { lng, lat } = addressMap[fullAddress]
addressWithLocation.push([address, lat, lng])
}
dataOfDistrict.addressWithLocation = addressWithLocation
delete dataOfDistrict.addresses
}
await writeFile(`docs/data/${basename(dateJson)}`, JSON.stringify(dataOfDate))
}