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 });
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.