bagdad/main.ts

28 lines
719 B
TypeScript
Raw Normal View History

2024-10-17 20:45:29 +00:00
#!/usr/bin/env -S npx tsx
2024-11-15 20:42:19 +00:00
import { notify } from "./src/bot.js";
import { getFirstAvailableAppointment } from "./src/appointments.js";
2021-12-11 22:30:35 +00:00
2024-11-15 20:42:19 +00:00
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);
2021-12-11 21:01:50 +00:00
}
2024-11-15 20:42:19 +00:00
const sleep = async (ms: number) => new Promise(r => setTimeout(r, ms));
while (true) {
await run();
await sleep(60_000);
}