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
import { getWeather } from "https://esm.town/v/chet/getWeather";
import { email } from "https://esm.town/v/std/email?v=11";
import process from "node:process";
const toInches = (cm: number) => Math.round(cm * 2.54 * 10) / 10;
/** This doesnt work well */
export async function powderNotify(location: string) {
const weather = await getWeather(location);
const snowDays = weather.forecast.forecastday.filter(day => {
if (day.day.daily_chance_of_snow < 50) return false;
if (day.day.totalsnow_cm < 3) return false;
return true;
});
if (snowDays.length === 0) {
console.log("No upcoming snow days in " + location);
return;
}
console.log(snowDays.length + " upcoming snow days in " + location);
const body = snowDays
.map(day => {
const inches = toInches(day.day.totalsnow_cm);
return `- ${day.date}: ${inches}in snow, ${day.day.maxtemp_f}°F temp, ${day.day.maxwind_mph}mph wind`;
})
.join("\n");
const total = snowDays.map(day => toInches(day.day.totalsnow_cm)).reduce((sum, x) => sum + x, 0);
const subject = `${total}in of snow coming to ${location}`;
await email({ subject, text: body });
}
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
//
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 });
}
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
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);
// 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 });
}
1
2
3
4
5
6
7
8
9
10
11
12
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
import { load } from "npm:cheerio";
export async function latLngOfCity(args: { cityName: string }) {
const { cityName } = args;
const html = await fetchText(
`https://en.wikipedia.org/wiki/${cityName}`,
);
const $ = load(html);
const lat_lng = $("span.geo-default > span").first().text();
return lat_lng;
}
1
Next