diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2026-05-06 21:46:21 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2026-05-06 21:46:21 +0300 |
| commit | 713ced9c68cd70a8e56e8ce5ed27cb9bbe3e55c4 (patch) | |
| tree | 29f9997386b9f46db9f263ef63a5e01ca19db393 /src/index.ts | |
| parent | cba8c3d49b53702a488eaff16109e29e49d94b6d (diff) | |
Add shopping list features, rework
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index c6d92eb..0000000 --- a/src/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { buildSheetsClient } from "./sheets"; -import { broadcastMessage } from "./tg"; - -const main = async (): Promise<void> => { - const startTime = Date.now(); - console.log("[run] Starting recurring tasks notification script"); - - const sheets = await buildSheetsClient(); - - // 1. Fetch raw sheet data - const sheetData = await sheets.fetchSheetData(); - console.log(`[run] Retrieved ${sheetData.length} raw rows from Sheets`); - - // 2. Process rows (compute next/last dates) - const entries = sheets.processRows(sheetData); - console.log(`[run] Processed ${entries.length} entries`); - - // 3. Filter only tasks due this week - const thisWeeksEntries = sheets.filterOnlyThisWeek(entries); - console.log(`[run] Found ${thisWeeksEntries.length} entries due this week`); - - // 4. Compose & broadcast Telegram message - if (thisWeeksEntries.length > 0) { - const tasks = thisWeeksEntries.map((e) => `${e.name} (${e.interval})`); - const taskText = tasks.join("\n"); - const msg = `Tällä viikolla tehtävät hommat:\n${taskText}`; - await broadcastMessage(msg); - console.log("[run] Broadcasted weekly task message"); - } else { - const msg = "Tällä viikolla ei toistuvia hommia! 🎉"; - await broadcastMessage(msg); - console.log("[run] Broadcasted empty-week message"); - } - - // 5. Update "last done" column with new date stamps (only tasks done this week are advanced) - const newDateStamps = sheets.updatedLastDoneDateStamps(entries); - await sheets.updateSheetLastDoneColumn(newDateStamps); - console.log("[run] Updated last done column in sheet"); - - const durationMs = Date.now() - startTime; - console.log(`[run] Completed successfully in ${durationMs}ms`); -}; - -main() - .then(() => { - process.exit(0); - }) - .catch((err) => { - console.error("[run] Fatal error:", err); - process.exit(1); - }); |
