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
import { nowcastPMAqi } from "https://esm.town/v/russbiggs/nowcastPMAqi";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let emailNowcastPMAqi = async () => {
const dateFrom = new Date(Date.now() - 12 * 60 * 60 * 1000); // get previous 12 hours of data
const dateTo = new Date();
let res = await fetchJSON(
"https://api.openaq.org/v2/measurements?" +
new URLSearchParams({
limit: "100",
page: "1",
location_id: "827", //
date_from: dateFrom.toISOString(),
date_to: dateTo.toISOString(),
parameter: "pm25",
order_by: "datetime",
})
);
const values = res.results.map((o) => o.value);
const aqi = await nowcastPMAqi(values);
console.email(
`The AQI at ${res.results[0].location} is ${aqi}`,
`The AQI report`
);
};
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