1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { getWeather } from "https://esm.town/v/chet/getWeather";
import { email } from "https://esm.town/v/std/email";
export async function frostNotify(
where: string,
minTempF = 33,
) {
const forecast = await getWeather(where, 10);
const frosts = forecast.forecast.forecastday.filter((day) => day.day.mintemp_f <= minTempF);
if (frosts.length === 0)
return console.log("No Upcoming Frost");
const body = frosts
.map((day) => `- ${day.date}: ${day.day.mintemp_f}°F`)
.join("\n");
console.log("Upcoming Frost");
const subject = `Frost Warning for ${where}: ${frosts[0].date}`;
const verb = frosts.length === 1 ? "is" : "are";
const plural = frosts.length === 1 ? "day" : "days";
const message = `There ${verb} ${frosts.length} upcoming frost ${plural} in ${where}\n${body}`;
await email({ subject, text: message });
}