Update list-weather.ps1

This commit is contained in:
Markus Fleschutz 2022-11-25 15:04:10 +01:00
parent 6531d14f66
commit 985db706ad

View File

@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Lists the weather report Lists the weather report
.DESCRIPTION .DESCRIPTION
This PowerShell script lists the hourly weather report. This PowerShell script lists the hourly weather report in a nice table.
.PARAMETER Location .PARAMETER Location
Specifies the location to use (determined automatically per default) Specifies the location to use (determined automatically per default)
.EXAMPLE .EXAMPLE
@ -15,8 +15,8 @@
param([string]$Location = "") # empty means determine automatically param([string]$Location = "") # empty means determine automatically
function Describe { param([string]$Desc) function GetDescription { param([string]$Text)
switch($Desc) { switch($Text) {
"Blizzard" { return "❄️ blizzard" } "Blizzard" { return "❄️ blizzard" }
"Clear" { return "🌙 clear " } "Clear" { return "🌙 clear " }
"Cloudy" { return "☁️ cloudy " } "Cloudy" { return "☁️ cloudy " }
@ -34,7 +34,22 @@ function Describe { param([string]$Desc)
"Patchy rain possible" { return "💧 patchy rain possible" } "Patchy rain possible" { return "💧 patchy rain possible" }
"Sunny" { return "☀️ sunny " } "Sunny" { return "☀️ sunny " }
"Thundery outbreaks possible" { return "thundery outbreaks possible" } "Thundery outbreaks possible" { return "thundery outbreaks possible" }
default { return "$Desc" } default { return "$Text" }
}
}
function GetWindDir { param([string]$Text)
switch($Text) {
"N" { return "" }
"E" { return "" }
"ESE" { return "" }
"SE" { return "" }
"S" { return "" }
"SSW" { return "" }
"SW" { return "" }
"WSW" { return "" }
"W" { return "" }
default { return "$Text" }
} }
} }
@ -51,13 +66,14 @@ try {
$Humidity = $Hourly.humidity $Humidity = $Hourly.humidity
$Pressure = $Hourly.pressure $Pressure = $Hourly.pressure
$WindSpeed = $Hourly.windspeedKmph $WindSpeed = $Hourly.windspeedKmph
$WindDir = $Hourly.winddir16Point $WindDir = GetWindDir $Hourly.winddir16Point
$UV = $Hourly.uvIndex $UV = $Hourly.uvIndex
$Clouds = $Hourly.cloudcover $Clouds = $Hourly.cloudcover
$Desc = $Hourly.weatherDesc.value $Visib = $Hourly.visibility
$Desc = GetDescription $Hourly.weatherDesc.value
if ($Hour -eq 0) { if ($Hour -eq 0) {
if ($Day -eq 0) { if ($Day -eq 0) {
Write-Host -foregroundColor green "Today 🌡°C ☂mm 💧 💨km/h from ☀UV ☁️ at $Area ($Region, $Country)" Write-Host -foregroundColor green "TODAY 🌡°C ☂mm 💧 💨km/h ☀UV ☁️ at $Area ($Region, $Country)"
} elseif ($Day -eq 1) { } elseif ($Day -eq 1) {
Write-Host -foregroundColor green "Tomorrow" Write-Host -foregroundColor green "Tomorrow"
} else { } else {
@ -65,7 +81,7 @@ try {
} }
$Day++ $Day++
} }
"$(($Hour.toString()).PadLeft(2))°° $(($Temp.toString()).PadLeft(2))° $($Precip) $(($Humidity.toString()).PadLeft(3))% $(($WindSpeed.toString()).PadLeft(2)) $WindDir`t$($UV) $(($Clouds.toString()).PadLeft(3))% $(Describe $Desc)" "$(($Hour.toString()).PadLeft(2))°° $(($Temp.toString()).PadLeft(2))° $($Precip) $(($Humidity.toString()).PadLeft(3))% $(($WindSpeed.toString()).PadLeft(2)) $WindDir`t$($UV) $(($Clouds.toString()).PadLeft(3))% $Desc"
$Hour++ $Hour++
} }
exit 0 # success exit 0 # success