-
Notifications
You must be signed in to change notification settings - Fork 166
/
fetch-vaccination-database.ts
57 lines (51 loc) · 1.81 KB
/
fetch-vaccination-database.ts
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
import fs from "fs";
import path from "path";
import fetch from "cross-fetch";
import {
VaccinationRegionsResponse,
VaccinationRegion,
VaccinationContact,
} from "../../lib/data/vaccination";
import { getKebabCase } from "../../lib/string-utils";
const vaksinId = "https://api.vaksinasi.id";
export async function fetchVaccinationDatabase() {
const regions = (await (
await fetch(`${vaksinId}/regions`)
).json()) as VaccinationRegionsResponse;
const locations: { [province: string]: VaccinationContact[] } = {};
const promisedLocations = [];
for (const { province } of regions.data) {
promisedLocations.push(
fetch(`${vaksinId}/locations/${province}`)
.then((res) => res.json() as unknown as VaccinationRegion)
.then((region) => {
locations[region.data[0].province] = region.data.map((location) => ({
id: `${region.data.findIndex(
(index) => location.title === index.title,
)}`,
keterangan: "Lokasi Vaksinasi COVID-19",
lokasi: location.city,
verifikasi: location.isvalid ? 1 : 0,
penyedia: location.title,
alamat: location.address,
slug: getKebabCase(location.title),
informasi_2: location.description,
terakhir_update: location.dateadded,
rentang_umur: location.agerange,
buka_waktu: location.timestart,
tutup_waktu: location.timeend,
mulai_tanggal: location.datestart,
selesai_tanggal: location.dateend,
link: location.link,
map: location.map,
}));
}),
);
}
await Promise.all(promisedLocations);
const text = JSON.stringify(locations);
fs.writeFileSync(
path.resolve(__dirname, "../../data/wbw-vaccination-database.json"),
text,
);
}