PowerShell/docs/list-nina-warnings.md

108 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2024-11-08 12:38:20 +01:00
The *list-nina-warnings.ps1* Script
===========================
2023-12-07 20:24:45 +01:00
2024-08-15 09:51:46 +02:00
This PowerShell script queries the current NINA warnings and lists it.
2023-12-07 20:24:45 +01:00
Parameters
----------
```powershell
2024-11-08 12:35:11 +01:00
/home/markus/Repos/PowerShell/scripts/list-nina-warnings.ps1 [[-ARS] <String>] [<CommonParameters>]
2024-05-19 10:25:56 +02:00
2024-08-15 09:51:46 +02:00
-ARS <String>
Specifies the official regional key in Germany ("Amtlicher Regionalschlüssel", e.g. 09777, none by default)
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
2023-12-07 20:24:45 +01:00
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2024-08-15 09:51:46 +02:00
Example
-------
```powershell
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)
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
2023-12-07 20:24:45 +01:00
Script Content
--------------
```powershell
<#
.SYNOPSIS
2024-08-15 09:51:46 +02:00
Lists the current NINA warnings
2023-12-07 20:24:45 +01:00
.DESCRIPTION
2024-08-15 09:51:46 +02:00
This PowerShell script queries the current NINA warnings and lists it.
.PARAMETER ARS
Specifies the official regional key in Germany ("Amtlicher Regionalschlüssel", e.g. 09777, none by default)
2023-12-07 20:24:45 +01:00
.EXAMPLE
PS> ./list-nina-warnings.ps1
2024-08-15 09:51:46 +02:00
⚠️ 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)
2023-12-07 20:24:45 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-08-15 09:51:46 +02:00
param([string]$ARS = "")
function ListWarningsOf([string]$source, [string]$URL)
2024-05-19 10:25:56 +02:00
{
2024-08-15 09:51:46 +02:00
Write-Progress "Loading NINA - $source warnings..."
$warnings = (Invoke-WebRequest -URI $URL -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
2023-12-07 20:24:45 +01:00
Write-Progress -completed "Done."
2024-05-19 10:25:56 +02:00
2023-12-07 20:24:45 +01:00
foreach($warning in $warnings) {
2024-08-15 09:51:46 +02:00
$title = $warning.i18nTitle.en
if ("$title" -eq "") { $title = $warning.i18nTitle.de }
2023-12-07 20:24:45 +01:00
$startDate = $warning.startDate
$expiresDate = $warning.expiresDate
$severity = $warning.severity
$urgency = $warning.urgency
$type = $warning.type
2024-05-19 10:25:56 +02:00
Write-Output ""
2024-08-15 09:51:46 +02:00
Write-Output "⚠️ $title"
if ("$type" -ne "") {
Write-Output " 🕘 $($startDate)...$expiresDate (by $source, $type, $severity, $urgency)"
}
2023-12-07 20:24:45 +01:00
}
2024-05-19 10:25:56 +02:00
}
try {
2024-08-15 09:51:46 +02:00
if ("$ARS" -ne "") {
ListWarningsOf "Region" "https://warnung.bund.de/api31/dashboard/$($ARS)0000000.json"
} else {
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"
}
2023-12-07 20:24:45 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:56)*