mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 01:18:18 +02:00
Added weather-alert.ps1
This commit is contained in:
parent
39e4fe8c1b
commit
af115fc932
@ -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
|
* [txt2wav.ps1](Scripts/txt2wav.ps1) - converts text into a audio .WAV file
|
||||||
* [validate-xml.ps1](Scripts/validate-xml.ps1) - validates the given XML file
|
* [validate-xml.ps1](Scripts/validate-xml.ps1) - validates the given XML file
|
||||||
* [weather.ps1](Scripts/weather.ps1) - prints the current weather forecast
|
* [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-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
|
* [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
|
* [wakeup.ps1](Scripts/wakeup.ps1) - sends a magic packet to the given computer, waking him up
|
||||||
|
36
Scripts/weather-alert.ps1
Executable file
36
Scripts/weather-alert.ps1
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user