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
import { msDay } from "https://esm.town/v/stevekrouse/msDay";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
// deprecated in favor of @stevekrouse.openAQLocation
export let aqiLocation = async ({ lat, lon }: { lat: number; lon: number }) => {
const { results } = fetchJSON(
"https://api.openaq.org/v2/locations?" +
new URLSearchParams({
limit: "10",
page: "1",
offset: "0",
sort: "asc",
radius: "10000",
order_by: "distance",
dumpRaw: "false",
coordinates: lat.toPrecision(8) + "," + lon.toPrecision(8),
entity: "government",
parameter_id: 2, // PM2.5
})
);
return results.find(
(location) =>
new Date() -
new Date(
location.parameters.find((p) => p.parameter === "pm25").lastUpdated
) <
msDay
);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023