Updated list-nina-warnings.ps1

This commit is contained in:
Markus Fleschutz 2024-06-26 08:39:06 +02:00
parent 31a95d7074
commit 1c92a03ad5

View File

@ -1,42 +1,46 @@
<#
.SYNOPSIS
Lists the current weather warnings by NINA
Lists the current NINA warnings
.DESCRIPTION
This PowerShell script queries the current NINA weather warnings and lists it.
This PowerShell script queries the current NINA warnings and lists it.
.EXAMPLE
PS> ./list-nina-warnings.ps1
Official SEVERE WEATHER WARNING of SEVERE THUNDERSTORMS with VERY HEAVY RAIN and HAIL
🕘 2024-06-26T07:53:00+02:00 ... 2024-06-26T08:45:00+02:00 (by DWD, Update, Severe, Immediate)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function ListWarningsOf([string]$category, [string]$source)
function ListWarningsOf([string]$source, [string]$URL)
{
Write-Progress "Loading NINA warnings..."
$warnings = (Invoke-WebRequest -URI https://warnung.bund.de/api31/$category/mapData.json -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
Write-Progress "Loading NINA - $source warnings..."
$warnings = (Invoke-WebRequest -URI $URL -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
Write-Progress -completed "Done."
foreach($warning in $warnings) {
$message = $warning.i18nTitle.en
$title = $warning.i18nTitle.en
if ("$title" -eq "") { $title = $warning.i18nTitle.de }
$startDate = $warning.startDate
$expiresDate = $warning.expiresDate
$severity = $warning.severity
$urgency = $warning.urgency
$type = $warning.type
Write-Output "* $message"
Write-Output " from $startDate to $expiresDate ($source $type, $severity, $urgency)"
Write-Output "⚠️ $title"
Write-Output " 🕘 $($startDate)...$expiresDate (by $source, $type, $severity, $urgency)"
Write-Output ""
}
}
try {
Write-Output ""
ListWarningsOf "katwarn" "Katwarn"
ListWarningsOf "dwd" "DWD"
ListWarningsOf "police" "Police"
ListWarningsOf "lhp" "LHP"
ListWarningsOf "biwapp" "Biwapp"
ListWarningsOf "Katwarn" "https://warnung.bund.de/api31/katwarn/mapData.json"
ListWarningsOf "DWD" "https://warnung.bund.de/api31/dwd/mapData.json"
ListWarningsOf "Police" "https://warnung.bund.de/api31/police/mapData.json"
ListWarningsOf "LHP" "https://warnung.bund.de/api31/lhp/mapData.json"
ListWarningsOf "Biwapp" "https://warnung.bund.de/api31/biwapp/mapData.json"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"