enable looping so the script can handle scheduling
Security / security (push) Successful in 1m7s

This commit is contained in:
2026-05-13 21:09:52 -05:00
parent 90a2805339
commit 998f639a55
2 changed files with 59 additions and 40 deletions
+57 -39
View File
@@ -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
}