This commit is contained in:
+57
-39
@@ -3,6 +3,7 @@
|
|||||||
[string] $dtAPIKey = $ENV:DONETICKAPIKEY
|
[string] $dtAPIKey = $ENV:DONETICKAPIKEY
|
||||||
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
||||||
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
||||||
|
[int[]] $notificationTimes = $ENV:NOTIFICATIONTIMES | Sort-Object
|
||||||
|
|
||||||
|
|
||||||
function Send-Notification
|
function Send-Notification
|
||||||
@@ -50,54 +51,71 @@ function Get-Chores
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$today = (Get-Date "23:59:59")
|
while ($true) {
|
||||||
$chores = Get-Chores
|
$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
|
if ($chore.nextDueDate)
|
||||||
if (($dueDate - $today).Days -lt 0) #OVERDUE
|
|
||||||
{
|
{
|
||||||
write-host "$($chore.name) $dueDate is overdue!"
|
$dueDate = Get-Date $chore.nextDueDate
|
||||||
$overdueTasks += $chore
|
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!"
|
$content += "$($overdueTask.Name) was due $(Get-Date $overdueTask.nextDueDate -Format "MM/dd/yyyy HH:mm")`n"
|
||||||
$todaysTasks += $chore
|
|
||||||
# Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!"
|
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
Write-Host "Finding next notification time..."
|
||||||
|
foreach($time in $notificationTimes)
|
||||||
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 -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
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -9,4 +9,5 @@ services:
|
|||||||
- DONETICKPORT=8787 # donetick port
|
- DONETICKPORT=8787 # donetick port
|
||||||
- DONETICKAPIKEY=adminpass # donetick API key
|
- DONETICKAPIKEY=adminpass # donetick API key
|
||||||
- APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url
|
- APPRISEWEBHOOKURL=https://apprisehost/notify/config # apprise notification url
|
||||||
- APPRISEWEBHOOKTAG=all # apprise notification tag
|
- APPRISEWEBHOOKTAG=all # apprise notification tag
|
||||||
|
- NOTIFICATIONTIMES=8,12,17 # hours when notifications will be sent
|
||||||
Reference in New Issue
Block a user