Update list-nina-warnings.ps1

This commit is contained in:
Markus Fleschutz 2024-05-14 16:51:44 +02:00
parent 3721feeaa9
commit d6071ca2b0

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Lists the current NINA warnings Lists the current weather warnings by NINA
.DESCRIPTION .DESCRIPTION
This PowerShell script queries the current NINA warnings and prints it. This PowerShell script queries the current NINA weather warnings and lists it.
.EXAMPLE .EXAMPLE
PS> ./list-nina-warnings.ps1 PS> ./list-nina-warnings.ps1
.LINK .LINK
@ -11,21 +11,32 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
try { function ListWarningsOf([string]$category, [string]$source)
{
Write-Progress "Loading NINA warnings..." Write-Progress "Loading NINA warnings..."
$warnings = (Invoke-WebRequest -URI https://warnung.bund.de/api31/dwd/mapData.json -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json $warnings = (Invoke-WebRequest -URI https://warnung.bund.de/api31/$category/mapData.json -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
Write-Progress -completed "Done." Write-Progress -completed "Done."
Write-Output "Weather Warnings by DWD"
Write-Output "-----------------------"
foreach($warning in $warnings) { foreach($warning in $warnings) {
$message = $warning.i18nTitle.en
$startDate = $warning.startDate $startDate = $warning.startDate
$expiresDate = $warning.expiresDate $expiresDate = $warning.expiresDate
$severity = $warning.severity $severity = $warning.severity
$urgency = $warning.urgency $urgency = $warning.urgency
$type = $warning.type $type = $warning.type
$message = $warning.i18nTitle.en Write-Output "* $message"
Write-Output "* $type from $startDate to $($expiresDate): $message ($severity, $urgency)" Write-Output " from $startDate to $expiresDate ($source $type, $severity, $urgency)"
Write-Output ""
} }
}
try {
Write-Output ""
ListWarningsOf "katwarn" "Katwarn"
ListWarningsOf "dwd" "DWD"
ListWarningsOf "police" "Police"
ListWarningsOf "lhp" "LHP"
ListWarningsOf "biwapp" "Biwapp"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"