Back

Version 13

11/15/2023
import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";

import process from "node:process";

export async function aqi(interval: Interval) {
const location = "Portland, Oregon"; // <-- change to place, city, or zip code
const data = await easyAQI({ location });
if (!interval.lastRunAt) {
const res = await fetchJSON(process.env.gotifyWebhookURL, {
method: "POST",
body: JSON.stringify({
"message": `You're now receiving AQI notifications!`,
}),
});
return res;
}
if (data.severity.includes("Unhealthy")) {
const res = await fetchJSON(process.env.gotifyWebhookURL, {
method: "POST",
body: JSON.stringify({
"message": `AQI in ${location} is ${data.aqi}`,
"priority": 7,
}),
});
return res;
}
}
Updated: November 15, 2023