PowerShell/Scripts/list-weather.ps1

48 lines
1.5 KiB
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-04-22 10:26:30 +02:00
.SYNTAX list-weather.ps1 [<location>]
.DESCRIPTION lists the hourly weather
2021-04-19 11:12:21 +02:00
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Location = "") # empty means determine automatically
try {
$Weather = (Invoke-WebRequest http://wttr.in/${Location}?format=j1 -UserAgent "curl" ).Content | ConvertFrom-Json
$Area = $Weather.nearest_area.areaName.value
$Region = $Weather.nearest_area.region.value
2021-04-20 16:38:04 +02:00
$Country = $Weather.nearest_area.country.value
2021-04-19 11:12:21 +02:00
2021-04-20 16:38:04 +02:00
[int]$Day = 0
2021-04-19 11:12:21 +02:00
foreach ($Hourly in $Weather.weather.hourly) {
2021-04-20 16:38:04 +02:00
$Hour = $Hourly.time / 100
2021-04-19 11:12:21 +02:00
$Temp = $Hourly.tempC
$Precip = $Hourly.precipMM
$Humidity = $Hourly.humidity
$Pressure = $Hourly.pressure
$WindSpeed = $Hourly.windspeedKmph
$WindDir = $Hourly.winddir16Point
$UV = $Hourly.uvIndex
$Clouds = $Hourly.cloudcover
$Desc = $Hourly.weatherDesc.value
2021-04-20 16:38:04 +02:00
if ($Hour -eq 0) {
if ($Day -eq 0) {
2021-04-22 14:06:58 +02:00
"🕗 🌡 ☂️ 💨 ☀️ ☁️ TODAY at $Area ($Region, $Country)"
2021-04-20 16:38:04 +02:00
} elseif ($Day -eq 1) {
2021-04-22 14:06:58 +02:00
" TOMORROW"
2021-04-20 16:38:04 +02:00
} else {
2021-04-22 14:06:58 +02:00
" DAY AFTER TOMORROW"
2021-04-20 16:38:04 +02:00
}
$Day++
}
2021-04-22 14:06:58 +02:00
"$($Hour)°°`t$($Temp)°C`t$($Precip)mm $($Humidity)% $($WindSpeed)km/h from $WindDir`tUV$($UV) $($Pressure)hPa $($Clouds)% $Desc"
2021-04-19 11:12:21 +02:00
$Hour++
}
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}