diff --git a/docs/radio-tracker.md b/docs/radio-tracker.md index 7719db8..9ef1865 100644 --- a/docs/radio-tracker.md +++ b/docs/radio-tracker.md @@ -21,3 +21,7 @@ Private (owner-only, 404 for everyone else) tracker for Opa Chiel's scanner hobb - Both read `~/.config/radio.env` (mode 600): `RADIO_NTFY_URL` (ntfy topic URL), optional `RADIO_NTFY_TOKEN`. Log: `~/.local/state/radio.log`. - `bun scripts/radio.ts upcoming` prints the next 24 h of reminders without sending. + +## Quiet hours + +Reminders whose send time (event minus 10 min) falls in 23:00-07:30 Europe/Amsterdam are skipped. Override with `RADIO_QUIET_HOURS=HH:MM-HH:MM` (or `off`) in `~/.config/radio.env`; the page shows the code default (`QUIET_HOURS` in `src/lib/radio/index.ts`). `bun scripts/radio.ts upcoming` marks skipped reminders as QUIET-SKIP. diff --git a/scripts/radio.ts b/scripts/radio.ts index 0e9af55..44aecc2 100644 --- a/scripts/radio.ts +++ b/scripts/radio.ts @@ -9,22 +9,30 @@ * * Reminders go to RADIO_NTFY_URL (an ntfy topic URL, optional RADIO_NTFY_TOKEN), passed in with * `docker exec --env-file ~/.config/radio.env`. radio.reminders makes every reminder fire once. + * RADIO_QUIET_HOURS (default 23:00-07:30, "off" to disable) skips reminders sent in that window. */ import postgres from 'postgres'; import * as sat from 'satellite.js'; import { ISS_DOWNLINK_HZ, ISS_MIN_EL, + QUIET_HOURS, REMIND_MINUTES, compass, fmtTime, formatFreq, - occurrences + inQuiet, + occurrences, + parseQuiet } from '../src/lib/radio/index'; if (!process.env.DB_URL) throw new Error('DB_URL is required'); const sql = postgres(process.env.DB_URL, { max: 2, onnotice: () => {} }); const mode = process.argv[2] ?? 'remind'; +// Quiet hours (Amsterdam): reminders whose send time falls inside are skipped. "off" disables. +const QUIET = parseQuiet(process.env.RADIO_QUIET_HOURS ?? QUIET_HOURS); +const sendAt = (at: Date) => new Date(at.getTime() - REMIND_MINUTES * 60_000); +const quiet = (at: Date) => inQuiet(sendAt(at), QUIET); const PAGE = 'https://stanrunge.dev/trackers/radio'; // Gouda (approx), 0 m. @@ -237,6 +245,7 @@ async function remind() { const now = new Date(); const list = await due(now, new Date(now.getTime() + REMIND_MINUTES * 60_000)); for (const r of list) { + if (quiet(r.at)) continue; const [claimed] = await sql`INSERT INTO radio.reminders (kind, ref_id, at) VALUES (${r.kind}, ${r.refId}, ${r.at}) ON CONFLICT DO NOTHING RETURNING at`; if (!claimed) continue; @@ -255,8 +264,11 @@ try { else if (mode === 'remind') await remind(); else if (mode === 'upcoming') { const now = new Date(); + console.log(`quiet hours: ${QUIET?.label ?? 'off'} (Europe/Amsterdam, by send time)`); for (const r of await due(now, new Date(now.getTime() + 86_400_000))) - console.log(`${r.at.toISOString()} ${r.kind}: ${r.title} | ${r.message}`); + console.log( + `${quiet(r.at) ? 'QUIET-SKIP' : 'SEND '} at ${fmtTime(sendAt(r.at))} ${r.kind}: ${r.title}` + ); } else throw new Error(`unknown mode ${mode} (iss | remind | upcoming)`); } finally { await sql.end(); diff --git a/src/lib/radio/IssPasses.svelte b/src/lib/radio/IssPasses.svelte index 28fc25d..6974e9c 100644 --- a/src/lib/radio/IssPasses.svelte +++ b/src/lib/radio/IssPasses.svelte @@ -4,10 +4,13 @@ import { ISS_DOWNLINK_HZ, ISS_MIN_EL, + QUIET_HOURS, + REMIND_MINUTES, compass, dayKey, fmtTime, formatFreq, + parseQuiet, relDay, until } from './index.js'; @@ -100,7 +103,8 @@
{/if} diff --git a/src/lib/radio/Nets.svelte b/src/lib/radio/Nets.svelte index 3c8e3ea..19e30f8 100644 --- a/src/lib/radio/Nets.svelte +++ b/src/lib/radio/Nets.svelte @@ -12,7 +12,9 @@ BANDS, BAND_LABEL, DAY_SHORT, + QUIET_HOURS, REMIND_MINUTES, + parseQuiet, daysLabel, fmtTime, formatFreq, @@ -118,7 +120,8 @@