Rename to check-weather.ps1

This commit is contained in:
Markus 2021-04-19 19:20:49 +02:00
parent 5eaef30837
commit f8eaf73614
4 changed files with 54 additions and 40 deletions

View File

@ -13,6 +13,7 @@ check-mac-address.ps1, checks the given MAC address for validity
check-ping.ps1, checks the ping latency to the internet
check-swap-space.ps1, checks the swap space for free space left
check-symlinks.ps1, checks every symlink in the given directory tree
check-weather.ps1, checks the current weather for critical values
check-windows-system-files.ps1, checks the validity of the Windows system files
check-xml-file.ps1, checks the given XML file for validity
cherry-picker.ps1, cherry-picks a Git commit into multiple branches
@ -171,7 +172,6 @@ unmute-audio.ps1, unmutes audio
upload-file.ps1, uploads the local file to the given FTP server
voice-control.ps1, executes the PowerShell scripts by voice
weather.ps1, prints the current weather forecast
weather-alert.ps1, checks the current weather for critical values
weather-report.ps1, prints the local weather report
wakeup.ps1, sends a magic packet to the given computer, waking him up
write-animated.ps1, writes animated text

Can't render this file because it has a wrong number of fields in line 163.

View File

@ -160,6 +160,7 @@ Mega Collection of PowerShell Scripts
* [check-ipv4-address.ps1](Scripts/check-ipv4-address.ps1) - checks the given IPv4 address for validity
* [check-ipv6-address.ps1](Scripts/check-ipv6-address.ps1) - checks the given IPv6 address for validity
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
* [check-weather.ps1](Scripts/check-weather.ps1) - checks the current weather for critical values
* [convert-csv2txt.ps1](Scripts/convert-csv2txt.ps1) - converts the given CSV file to a text list
* [convert-mysql2csv.ps1](Scripts/convert-mysql2csv.ps1) - converts the MySQL database table to a CSV file
* [convert-sql2csv.ps1](Scripts/convert-sql2csv.ps1) - converts the SQL database table to a CSV file
@ -197,7 +198,6 @@ Mega Collection of PowerShell Scripts
* [translate-files.ps1](Scripts/translate-files.ps1) - translates the given text files into any supported language
* [translate-text.ps1](Scripts/translate-text.ps1) - translates the given text in English into other languages
* [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
* [write-animated.ps1](Scripts/write-animated.ps1) - writes animated text
* [write-big.ps1](Scripts/write-big.ps1) - writes the given text in big letters

52
Scripts/check-weather.ps1 Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/pwsh
<#
.SYNTAX check-weather.ps1 [<location>]
.DESCRIPTION checks the weather for critical values
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Location = "") # empty means determine automatically
function Check { param([int]$Value, [int]$NormalMin, [int]$NormalMax, [string]$Unit)
if ($Value -lt $NormalMin) {
return "$Value $Unit ! "
}
if ($Value -gt $NormalMax) {
return "$Value $Unit ! "
}
return ""
}
try {
$Weather = (Invoke-WebRequest http://wttr.in/${Location}?format=j1 -UserAgent "curl" ).Content | ConvertFrom-Json
$Temp = $Weather.current_condition.temp_C
$Precip = $Weather.current_condition.precipMM
$Humidity = $Weather.current_condition.humidity
$Pressure = $Weather.current_condition.pressure
$WindSpeed = $Weather.current_condition.windspeedKmph
$WindDir = $Weather.current_condition.winddir16Point
$UV = $Weather.current_condition.uvIndex
$Visib = $Weather.current_condition.visibility
$Clouds = $Weather.current_condition.cloudcover
$Desc = $Weather.current_condition.weatherDesc.value
$Area = $Weather.nearest_area.areaName.value
$Region = $Weather.nearest_area.region.value
"Now: $($Temp)°C $($Precip)mm $($Humidity)% $($WindSpeed)km/h from $WindDir $($Pressure)hPa UV$($UV) $($Visib)km $($Clouds)% $Desc at $Area ($Region)"
$Result+=Check $Weather.current_condition.windspeedKmph 0 48 "km/h"
$Result+=Check $Weather.current_condition.visibility 1 1000 "km visibility"
$Result+=Check $Weather.current_condition.temp_C -20 40 "°C"
$Result+=Check $Weather.current_condition.uvIndex 0 6 "UV"
if ($Result -eq "") {
"Calm weather"
} else {
"WEATHER ALERT: $Result"
}
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -1,38 +0,0 @@
#!/usr/bin/pwsh
<#
.SYNTAX weather-alert.ps1
.DESCRIPTION checks the current weather for critical values
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
$GeoLocation="" # empty means determine automatically
function Check { param([int]$Value, [int]$NormalMin, [int]$NormalMax, [string]$Unit)
if ($Value -lt $NormalMin) {
return "$Value $Unit ! "
}
if ($Value -gt $NormalMax) {
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.visibility 1 1000 "km visibility"
$Result+=Check $Weather.current_condition.temp_C -20 40 "°C"
$Result+=Check $Weather.current_condition.uvIndex 0 6 "UV"
if ($Result -eq "") {
echo "No weather alert"
} else {
echo "WEATHER ALERT: $Result"
}
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}