Update list-weather.ps1

This commit is contained in:
Markus Fleschutz 2022-11-05 14:50:19 +01:00
parent 4ab6f26645
commit afe68edf1a

View File

@ -15,14 +15,26 @@
param([string]$Location = "") # empty means determine automatically param([string]$Location = "") # empty means determine automatically
function Describe { param([string]$Desc)
switch($Desc) {
"Clear" { return "clear " }
"Cloudy" { return "cloudy " }
"Light drizzle" { return "💧light drizzle" }
"Light rain shower" { return "💧light rain " }
"Mist" { return "🌫 misty " }
"Partly cloudy" { return "bit cloudy " }
"Sunny" { return "sunny " }
default { return "$Desc" }
}
}
try { try {
$Weather = (Invoke-WebRequest -URI http://wttr.in/${Location}?format=j1 -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json $Weather = (Invoke-WebRequest -URI http://wttr.in/${Location}?format=j1 -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$Area = $Weather.nearest_area.areaName.value $Area = $Weather.nearest_area.areaName.value
$Region = $Weather.nearest_area.region.value $Region = $Weather.nearest_area.region.value
$Country = $Weather.nearest_area.country.value $Country = $Weather.nearest_area.country.value
[int]$Day = 0 [int]$Day = 0
foreach ($Hourly in $Weather.weather.hourly) { foreach($Hourly in $Weather.weather.hourly) {
$Hour = $Hourly.time / 100 $Hour = $Hourly.time / 100
$Temp = $Hourly.tempC $Temp = $Hourly.tempC
$Precip = $Hourly.precipMM $Precip = $Hourly.precipMM
@ -35,18 +47,17 @@ try {
$Desc = $Hourly.weatherDesc.value $Desc = $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 ☂️ 💧 💨 from ☀UV ☁️ at $Area ($Region, $Country)" Write-Host -foregroundColor green "Today 🌡°C ☂mm 💧 💨km/h from ☀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 {
write-host -foregroundColor green "DAY AFTER TOMORROW" Write-Host -foregroundColor green "Day after tomorrow"
} }
$Day++ $Day++
} }
"$(($Hour.toString()).PadLeft(2))°° $(($Temp.toString()).PadLeft(2))° $($Precip)mm $(($Humidity.toString()).PadLeft(3))% $(($WindSpeed.toString()).PadLeft(2))km/h $WindDir`t$($UV) $(($Clouds.toString()).PadLeft(3))% $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))% $(Describe $Desc)"
$Hour++ $Hour++
} }
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"