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) {
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,
});
console.email(messageText, messageText);
}