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
import { databaseVal } from "https://esm.town/v/realog/databaseVal";
import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=3";
export async function aqiNotifier(location) {
// The realtime Air Quality Index (AQI) for any location
const myAQI = await easyAQI({
location: location,
});
const previousAQI = databaseVal.pop();
let direction = "";
if (myAQI.aqi < previousAQI.AQI) {
direction = "improving";
}
else if (myAQI.aqi > previousAQI.AQI) {
direction = "getting worse";
}
else {
direction = "stable";
}
const messageText =
`The AQI is ${direction} at ${myAQI.aqi} which is categorized as ${myAQI.severity}.`;
databaseVal.splice(0, databaseVal.length);
const storeAQI = databaseVal.push({
"AQI": Number(myAQI.aqi),
"severity": myAQI.severity,
"direction": direction,
});
// if (
// (previousAQI.severity == "Good" &&
// myAQI.severity == "Good")
// ) {
// return;
// }
// {
console.email(messageText, messageText);
}