diff --git a/README.md b/README.md index 5ca6b849..c777b883 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ The following PowerShell scripts can be found in the `Scripts/` subfolder: * [txt2wav.ps1](Scripts/txt2wav.ps1) - converts text into a audio .WAV file * [validate-xml.ps1](Scripts/validate-xml.ps1) - validates the given XML file * [weather.ps1](Scripts/weather.ps1) - prints the current weather forecast +* [weather-alert.ps1](Scripts/weather-alert.ps1) - checks the current weather for critical values * [weather-report.ps1](Scripts/weather-report.ps1) - prints the local weather report * [weather-worldwide.ps1](Scripts/weather-worldwide.ps1) - prints the current weather of cities world-wide * [wakeup.ps1](Scripts/wakeup.ps1) - sends a magic packet to the given computer, waking him up diff --git a/Scripts/weather-alert.ps1 b/Scripts/weather-alert.ps1 new file mode 100755 index 00000000..8d6d8270 --- /dev/null +++ b/Scripts/weather-alert.ps1 @@ -0,0 +1,36 @@ +#!/snap/bin/powershell + +# Syntax: ./weather-alert.ps1 +# Description: checks the current weather for critical values +# Author: Markus Fleschutz +# Source: github.com/fleschutz/PowerShell +# License: CC0 + +$GeoLocation="" # empty means determine automatically + +function Check { + param ([int]$Value, [int]$Min, [int]$Max, [string]$Unit) + if ($Value -lt $Min) { + return "$Value $Unit !" + } + if ($Value -gt $Max) { + return "$Value $Unit !" + } + return "" +} + +try { + $Weather=(Invoke-WebRequest http://wttr.in/${GeoLocation}?format=j1 -UserAgent "curl" ).Content | ConvertFrom-Json + + $Result+=Check $Weather.current_condition.windspeedKmph 0 48 "km/h" + $Result+=Check $Weather.current_condition.temp_C -20 35 "°C" + $Result+=Check $Weather.current_condition.uvIndex 0 10 "UV" + + if ($Result -eq "") { + echo "Calm weather" + } else { + echo "WEATHER ALERT: $Result" + } + exit 0 +} catch { Write-Error $Error[0] } +exit 1