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
29
30
31
32
33
34
35
36
37
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 = 1,
minTemp = 1,
) {
const forecast = await getWeather(where, 10);
// Could filter only for hours during the day.
// forecast.forecast.forecastday.map((day) => {
// day.hour.map((hour) => {
// const hourInt = parseInt(hour.time.split(" ")[1].split(":")[0]);
// if (hourInt >= 10 && hourInt <= 19) {
// // Filter only for hours during the day...
// }
// });
// });
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 });
console.log(string);
}
// Copilot output maxWind and maxTemp_f to hmtl
//
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 27, 2024