PowerShell/scripts/list-nina-warnings.ps1

45 lines
1.2 KiB
PowerShell
Raw Normal View History

2023-10-31 12:33:36 +01:00
<#
2023-10-30 14:04:09 +01:00
.SYNOPSIS
2024-05-14 16:51:44 +02:00
Lists the current weather warnings by NINA
2023-10-30 14:04:09 +01:00
.DESCRIPTION
2024-05-14 16:51:44 +02:00
This PowerShell script queries the current NINA weather warnings and lists it.
2023-10-30 14:04:09 +01:00
.EXAMPLE
PS> ./list-nina-warnings.ps1
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-05-14 16:51:44 +02:00
function ListWarningsOf([string]$category, [string]$source)
{
2023-10-30 14:04:09 +01:00
Write-Progress "Loading NINA warnings..."
2024-05-14 16:51:44 +02:00
$warnings = (Invoke-WebRequest -URI https://warnung.bund.de/api31/$category/mapData.json -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
2023-10-30 14:04:09 +01:00
Write-Progress -completed "Done."
2024-05-14 16:51:44 +02:00
2023-10-30 14:04:09 +01:00
foreach($warning in $warnings) {
2024-05-14 16:51:44 +02:00
$message = $warning.i18nTitle.en
2023-10-30 14:04:09 +01:00
$startDate = $warning.startDate
$expiresDate = $warning.expiresDate
$severity = $warning.severity
$urgency = $warning.urgency
$type = $warning.type
2024-05-14 16:51:44 +02:00
Write-Output "* $message"
Write-Output " from $startDate to $expiresDate ($source $type, $severity, $urgency)"
Write-Output ""
2023-10-30 14:04:09 +01:00
}
2024-05-14 16:51:44 +02:00
}
try {
Write-Output ""
ListWarningsOf "katwarn" "Katwarn"
ListWarningsOf "dwd" "DWD"
ListWarningsOf "police" "Police"
ListWarningsOf "lhp" "LHP"
ListWarningsOf "biwapp" "Biwapp"
2023-10-30 14:04:09 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}