From 998f639a55f1d6ae403c8219ea851b484d8b871a Mon Sep 17 00:00:00 2001 From: Kelly Thomas Reardon Date: Wed, 13 May 2026 21:09:52 -0500 Subject: [PATCH] enable looping so the script can handle scheduling --- Start-DoneTickNotifier.ps1 | 96 ++++++++++++++++++++++---------------- docker-compose.yaml | 3 +- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/Start-DoneTickNotifier.ps1 b/Start-DoneTickNotifier.ps1 index 4e8918e..9571bb1 100644 --- a/Start-DoneTickNotifier.ps1 +++ b/Start-DoneTickNotifier.ps1 @@ -3,6 +3,7 @@ [string] $dtAPIKey = $ENV:DONETICKAPIKEY [string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL [string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG +[int[]] $notificationTimes = $ENV:NOTIFICATIONTIMES | Sort-Object function Send-Notification @@ -50,54 +51,71 @@ function Get-Chores } } -$today = (Get-Date "23:59:59") -$chores = Get-Chores - -$overdueTasks = @() -$todaysTasks = @() - -foreach($chore in $chores) -{ - if ($chore.nextDueDate) +while ($true) { + $today = (Get-Date "23:59:59") + $chores = Get-Chores + + $overdueTasks = @() + $todaysTasks = @() + + foreach($chore in $chores) { - $dueDate = Get-Date $chore.nextDueDate - if (($dueDate - $today).Days -lt 0) #OVERDUE + if ($chore.nextDueDate) { - write-host "$($chore.name) $dueDate is overdue!" - $overdueTasks += $chore + $dueDate = Get-Date $chore.nextDueDate + if (($dueDate - $today).Days -lt 0) #OVERDUE + { + write-host "$($chore.name) $dueDate is overdue!" + $overdueTasks += $chore + } + elseif (($dueDate - $today) -lt 1) #due today + { + write-host "$($chore.name) $dueDate is due today!" + $todaysTasks += $chore + # Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!" + } + else + { + write-host "$($chore.name) $dueDate is due in the future" + } } - elseif (($dueDate - $today) -lt 1) #due today + + } + + if ($overdueTasks.Count -ne 0) + { + Write-Host "Sending a notification for $($overdueTasks.Count) overdue tasks" + $content = "The following tasks are overdue!`n" + foreach($overdueTask in $overdueTasks) { - write-host "$($chore.name) $dueDate is due today!" - $todaysTasks += $chore - # Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!" + $content += "$($overdueTask.Name) was due $(Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" } - else + Send-Notification -title "OVERDUE TASKS" -content $content + } + + if ($todaysTasks.Count -ne 0) + { + Write-Host "Sending a notification for $($todaysTasks.Count) tasks due today" + $content = "The following tasks are due today!`n" + foreach($task in $todaysTasks) { - write-host "$($chore.name) $dueDate is due in the future" + $content += "$($task.Name) is due $(Get-Date $task.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" } + Send-Notification -title "TODAY'S TASKS" -content $content } -} - -if ($overdueTasks.Count -ne 0) -{ - Write-Host "Sending a notification for $($overdueTasks.Count) overdue tasks" - $content = "The following tasks are overdue!`n" - foreach($overdueTask in $overdueTasks) + Write-Host "Finding next notification time..." + foreach($time in $notificationTimes) { - $content += "$($overdueTask.Name) was due $(Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" + $now = Get-Date + $diff = $now.Hour - $time + if ($diff -lt 0) # next notification time + { + Write-Host "Next notification time is $time`:00" + $sleepTime = ($diff * -1) * 60 + Write-Host "Sleeping for $sleepTime seconds" + Start-Sleep -Seconds $sleepTime + continue # leave loop + } } - Send-Notification -title "OVERDUE TASKS" -content $content -} - -if ($todaysTasks.Count -ne 0) -{ - Write-Host "Sending a notification for $($todaysTasks.Count) tasks due today" - $content = "The following tasks are due today!`n" - foreach($task in $todaysTasks) - { - $content += "$($task.Name) is due $(Get-Date $task.nextDueDate -Format "MM/dd/yyyy HH:mm")`n" - } - Send-Notification -title "TODAY'S TASKS" -content $content } \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index ef401c0..98bb9e9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,4 +9,5 @@ services: - DONETICKPORT=8787 # donetick port - DONETICKAPIKEY=adminpass # donetick API key - APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url - - APPRISEWEBHOOKTAG=all # apprise notification tag \ No newline at end of file + - APPRISEWEBHOOKTAG=all # apprise notification tag + - NOTIFICATIONTIMES=8,12,17 # hours when notifications will be sent \ No newline at end of file