PowerShell/docs/list-nina-warnings.md
2024-11-20 11:52:20 +01:00

108 lines
3.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

The *list-nina-warnings.ps1* Script
===========================
This PowerShell script queries the current NINA warnings and lists it.
Parameters
----------
```powershell
/home/markus/Repos/PowerShell/scripts/list-nina-warnings.ps1 [[-ARS] <String>] [<CommonParameters>]
-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
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
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
Script Content
--------------
```powershell
<#
.SYNOPSIS
Lists the current NINA warnings
.DESCRIPTION
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)
.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
#>
param([string]$ARS = "")
function ListWarningsOf([string]$source, [string]$URL)
{
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) {
$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 ""
Write-Output "⚠️ $title"
if ("$type" -ne "") {
Write-Output " 🕘 $($startDate)...$expiresDate (by $source, $type, $severity, $urgency)"
}
}
}
try {
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"
}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:56)*