bagdad/main.ts
2024-11-15 21:42:19 +01:00

28 lines
719 B
TypeScript
Executable File

#!/usr/bin/env -S npx tsx
import { notify } from "./src/bot.js";
import { getFirstAvailableAppointment } from "./src/appointments.js";
async function run() {
const availableAppointment = await getFirstAvailableAppointment();
if (!availableAppointment) {
console.log("no appt found");
return;
}
if (new Date() > availableAppointment) {
console.log("found one but already expired", availableAppointment.toISOString());
return;
}
console.log("found one", availableAppointment.toISOString());
await notify(availableAppointment);
}
const sleep = async (ms: number) => new Promise(r => setTimeout(r, ms));
while (true) {
await run();
await sleep(60_000);
}