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
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 aqiPushGotify(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;
}
}