import { getWeather } from "https://esm.town/v/chet/getWeather";
import { email } from "https://esm.town/v/std/email";
export async function sailingNotify(
where: string,
minWindMph = 10,
minTemp = 80,
) {
const forecast = await getWeather(where, 10);
const windy = forecast.forecast.forecastday.filter((day) =>
day.day.maxwind_mph >= minWindMph
&& day.day.maxtemp_f >= minTemp
);
if (windy.length === 0)
return console.log("Bad Upcoming Sailing Weather");
const body = windy
.map((day) => `- ${day.date}: ${day.day.maxwind_mph}mph`)
.join("\n");
console.log("Good Upcoming Sailing Weather");
const subject = `Good Sailing Weather for ${where}: ${windy[0].date}`;
const verb = windy.length === 1 ? "is" : "are";
const plural = windy.length === 1 ? "day" : "days";
const message = `There ${verb} ${windy.length} upcoming windy and warm ${plural} in ${where}\n${body}`;
await email({ subject, text: message });
}