Files
donetick-notifier/Start-DoneTickNotifier.ps1
2026-05-31 20:23:49 -05:00

70 lines
1.9 KiB
PowerShell

[string] $dtHost = $ENV:DONETICKHOST
[string] $dtPort = $ENV:DONETICKPORT
[string] $dtAPIKey = $ENV:DONETICKAPIKEY
Import-Module ./AppriseNotification.psm1
function Get-Chores
{
try {
$headers = @{
secretkey = $dtAPIKey
}
$results = Invoke-WebRequest -Uri "https://$dtHost`:$dtPort/eapi/v1/chore" -Method Get -Headers $headers
return ($results.Content | ConvertFrom-Json)
}
catch {
Write-Error "Error fetching chores: $($global:Error[0])"
}
}
$today = (Get-Date "23:59:59")
$chores = Get-Chores
$overdueTasks = @()
$todaysTasks = @()
foreach($chore in $chores)
{
if ($chore.nextDueDate)
{
$dueDate = (Get-Date $chore.nextDueDate).ToLocalTime()
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
}
else
{
write-host "$($chore.name) $dueDate is due in the future"
}
}
}
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)
{
$content += "$($overdueTask.Name) was due $((Get-Date $overdueTask.nextDueDate).ToLocalTime())`n"
}
Send-AppriseNotification -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).ToLocalTime())`n"
}
Send-AppriseNotification -title "TODAY'S TASKS" -content $content
}