first mvp
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
.env.ps1
|
.env.ps1
|
||||||
debug.ps1
|
debug.ps1
|
||||||
|
.postmate/postmate-history.json
|
||||||
|
|||||||
@@ -4,3 +4,73 @@
|
|||||||
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
||||||
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
||||||
|
|
||||||
|
|
||||||
|
function Send-Notification
|
||||||
|
{
|
||||||
|
param(
|
||||||
|
# Title of the notification
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$title,
|
||||||
|
|
||||||
|
# Content of the notification
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]
|
||||||
|
$content
|
||||||
|
)
|
||||||
|
|
||||||
|
$headers = @{
|
||||||
|
"Content-Type"="application/json"
|
||||||
|
}
|
||||||
|
$body = @{
|
||||||
|
title=$title
|
||||||
|
body=$content
|
||||||
|
tags="$appriseWebhookTag"
|
||||||
|
}
|
||||||
|
$json = $body | ConvertTo-Json
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -URI $appriseWebhookURL -Method post -Body $json -Headers $headers
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Notification Error Encountered: $($global:Error[0])"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
foreach($chore in $chores)
|
||||||
|
{
|
||||||
|
if ($chore.nextDueDate)
|
||||||
|
{
|
||||||
|
$dueDate = Get-Date $chore.nextDueDate
|
||||||
|
if (($dueDate - $today).Days -lt 0) #OVERDUE
|
||||||
|
{
|
||||||
|
write-host "$($chore.name) $dueDate is overdue!"
|
||||||
|
Send-Notification -title "OVERDUE TASK" -content "$($chore.Name) is overdue! Due date is $($chore.nextDueDate)"
|
||||||
|
}
|
||||||
|
elseif (($dueDate - $today) -lt 1) #due today
|
||||||
|
{
|
||||||
|
write-host "$($chore.name) $dueDate is due today!"
|
||||||
|
Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
write-host "$($chore.name) $dueDate is due in the future"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user