Back

Version 4

1/4/2025
import { email } from "https://esm.town/v/std/email?v=9";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
import { weatherGovGrid } from "https://esm.town/v/stevekrouse/weatherGovGrid";

export const umbrellaReminder = async (arg) => {
if (arg.method) return Response.json("");

let location = "queens"; // Customize this line
let [{ lat, lon }] = await nominatimSearch({ q: location });
let { properties: grid } = await weatherGovGrid({ lat, lon });
let { properties: { periods } } = await fetchJSON(grid.forecastHourly);

let { DateTime } = await import("npm:luxon");
let parse = (iso) => DateTime.fromISO(iso).setZone(grid.timeZone);
let today = periods.filter((x) =>
parse(x.startTime).toLocaleString() === DateTime.now().setZone(grid.timeZone).toLocaleString()
);

let format = (iso) => parse(iso).toFormat("ha").toLowerCase();

// Adjust message if low probability of rain all day
if (today.every((x) => x.probabilityOfPrecipitation.value < 30)) {
let html = `The probabilities of rain in ${location} today:\n\n`
+ today.map(({ startTime, endTime, probabilityOfPrecipitation: { value: p } }) =>
`${format(startTime)}-${format(endTime)}: ${p}%`
).join("\n");
console.log(html);
return today; // Return early if no significant rain
}

let html = `The probabilities of rain in <b>${location}</b> today:<br><br>`
+ today.map(({ startTime, endTime, probabilityOfPrecipitation: { value: p } }) =>
`${format(startTime)}-${format(endTime)}: ${p}%`
).join("<br>");

Updated: January 4, 2025