Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
import { fetch } from "https://esm.town/v/std/fetch";
export async function getMunichSwimCapacit() {
const organizationUnitIds = [
{ id: 30182, name: "Olympia-Schwimmhalle" },
{ id: 30184, name: "Nordbad" },
{ id: 30185, name: "Müller’sches Volksbad" },
{ id: 30187, name: "Südbad" },
{ id: 30188, name: "Schwimmbad 5" },
{ id: 30190, name: "Schwimmbad 6" },
{ id: 30191, name: "Schwimmbad 7" },
{ id: 30194, name: "Schwimmbad 8" },
{ id: 30195, name: "Schwimmbad 9" },
{ id: 30197, name: "Schwimmbad 10" },
{ id: 30199, name: "Westbad" },
{ id: 30201, name: "Schwimmbad 12" },
{ id: 30203, name: "Schwimmbad 13" },
{ id: 30204, name: "Schwimmbad 14" },
{ id: 30207, name: "Bad Forstenrieder Park" },
{ id: 30208, name: "Michaelibad" },
{ id: 30200, name: "Dantebad Sauna" },
];
async function fetchCount(id) {
const endpoint =
`https://functions.api.ticos-systems.cloud/api/gates/counter?organizationUnitIds=${id}`;
const response = await fetch(endpoint, {
headers: {
"abp-tenantid": "69",
accept: "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
pragma: "no-cache",
"sec-ch-ua": '"Not:A-Brand";v="99", "Chromium";v="112"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"macOS"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
},
referrer: "https://www.swm.de/",
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "omit",
});
const data = await response.json();
const { personCount, maxPersonCount } = data[0];
return { id, personCount, maxPersonCount };
}
async function populateUnits() {
for (let unit of organizationUnitIds) {
const populatedUnit = await fetchCount(unit.id);
unit.personCount = populatedUnit.personCount;
unit.maxPersonCount = populatedUnit.maxPersonCount;
}
}
await populateUnits();
return organizationUnitIds;
}
October 23, 2023