This commit is contained in:
+30
-12
@@ -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,14 +51,15 @@ function Get-Chores
|
||||
}
|
||||
}
|
||||
|
||||
$today = (Get-Date "23:59:59")
|
||||
$chores = Get-Chores
|
||||
while ($true) {
|
||||
$today = (Get-Date "23:59:59")
|
||||
$chores = Get-Chores
|
||||
|
||||
$overdueTasks = @()
|
||||
$todaysTasks = @()
|
||||
$overdueTasks = @()
|
||||
$todaysTasks = @()
|
||||
|
||||
foreach($chore in $chores)
|
||||
{
|
||||
foreach($chore in $chores)
|
||||
{
|
||||
if ($chore.nextDueDate)
|
||||
{
|
||||
$dueDate = Get-Date $chore.nextDueDate
|
||||
@@ -78,10 +80,10 @@ foreach($chore in $chores)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($overdueTasks.Count -ne 0)
|
||||
{
|
||||
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)
|
||||
@@ -89,10 +91,10 @@ if ($overdueTasks.Count -ne 0)
|
||||
$content += "$($overdueTask.Name) was due $(Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm")`n"
|
||||
}
|
||||
Send-Notification -title "OVERDUE TASKS" -content $content
|
||||
}
|
||||
}
|
||||
|
||||
if ($todaysTasks.Count -ne 0)
|
||||
{
|
||||
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)
|
||||
@@ -100,4 +102,20 @@ if ($todaysTasks.Count -ne 0)
|
||||
$content += "$($task.Name) is due $(Get-Date $task.nextDueDate -Format "MM/dd/yyyy HH:mm")`n"
|
||||
}
|
||||
Send-Notification -title "TODAY'S TASKS" -content $content
|
||||
}
|
||||
|
||||
Write-Host "Finding next notification time..."
|
||||
foreach($time in $notificationTimes)
|
||||
{
|
||||
$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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,3 +10,4 @@ services:
|
||||
- DONETICKAPIKEY=adminpass # donetick API key
|
||||
- APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url
|
||||
- APPRISEWEBHOOKTAG=all # apprise notification tag
|
||||
- NOTIFICATIONTIMES=8,12,17 # hours when notifications will be sent
|
||||
Reference in New Issue
Block a user