Runs every 1 hrs
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
import { today } from "https://esm.town/v/stungeye/today";
import { nowcastPMAQISeverity } from "https://esm.town/v/stevekrouse/nowcastPMAQISeverity?v=1";
import { nowCastPMAQI } from "https://esm.town/v/stungeye/nowCastPMAQI";
// # Email alerts when air is unhealthy near you
export async function aqiInProgress() {
async function mapLocationsToQuality(locations) {
const promises = Object.entries(locations).map(async ([name, id]) => {
const warningThresold = 75;
const results = await nowCastPMAQI({
location_id: id,
});
return {
name,
quality: {
quality: results,
severity: nowcastPMAQISeverity(results.aqi),
warn: results.now > warningThresold ||
results.then > warningThresold ||
results.aqi > warningThresold,
},
};
});
return (await Promise.all(promises)).reduce((acc, { name, quality }) => {
acc[name] = quality;
return acc;
}, {});
}
const locations = {
"Wildwood": 222033,
"St Charles": 70103,
"South Tuxedo": 230987,
"River East": 221546,
};
const qualities = await mapLocationsToQuality(locations);
const values = Object.keys(qualities).map((key) => qualities[key]);
const warning = values.some((v) => v.warn);
if (warning) {
console.email(
qualities,
"Air Quality Warning - " + today(),
);
}
}
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