2022-12-04 10:40:18 +01:00
|
|
|
|
## The *list-weather.ps1* Script
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
2022-12-04 10:40:18 +01:00
|
|
|
|
This PowerShell script lists the hourly weather report in a nice table.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
```powershell
|
2021-12-09 16:19:09 +01:00
|
|
|
|
list-weather.ps1 [[-Location] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
|
|
-Location <String>
|
|
|
|
|
Specifies the location to use (determined automatically per default)
|
|
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
|
Position? 1
|
|
|
|
|
Default value
|
|
|
|
|
Accept pipeline input? false
|
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
```powershell
|
|
|
|
|
PS> ./list-weather
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Notes
|
2022-11-17 19:46:02 +01:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
|
|
## Related Links
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
|
## Source Code
|
2022-11-17 20:05:34 +01:00
|
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Lists the weather report
|
|
|
|
|
.DESCRIPTION
|
2022-12-04 10:40:18 +01:00
|
|
|
|
This PowerShell script lists the hourly weather report in a nice table.
|
2022-11-17 20:02:26 +01:00
|
|
|
|
.PARAMETER Location
|
|
|
|
|
Specifies the location to use (determined automatically per default)
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./list-weather
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
param([string]$Location = "") # empty means determine automatically
|
|
|
|
|
|
2022-12-04 10:40:18 +01:00
|
|
|
|
function GetDescription { param([string]$Text)
|
|
|
|
|
switch($Text) {
|
|
|
|
|
"Blizzard" { return "❄️ blizzard ⚠️" }
|
|
|
|
|
"Clear" { return "🌙 clear" }
|
|
|
|
|
"Cloudy" { return "☁️ cloudy" }
|
|
|
|
|
"Fog" { return "🌫 fog" }
|
|
|
|
|
"Freezing fog" { return "🌫 freezing fog" }
|
|
|
|
|
"Heavy snow" { return "❄️ heavy snow ⚠️" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
"Light drizzle" { return "💧 light drizzle" }
|
2022-12-04 10:40:18 +01:00
|
|
|
|
"Light rain" { return "💧 light rain" }
|
2022-11-18 17:02:20 +01:00
|
|
|
|
"Light rain shower" { return "💧 light rain shower" }
|
2022-12-04 10:40:18 +01:00
|
|
|
|
"Light sleet" { return "❄️ light sleet" }
|
|
|
|
|
"Light snow" { return "❄️ light snow" }
|
|
|
|
|
"Light snow showers" { return "❄️ light snow showers" }
|
|
|
|
|
"Moderate snow" { return "❄️ moderate snow" }
|
|
|
|
|
"Mist" { return "🌫 misty" }
|
|
|
|
|
"Overcast" { return "☁️ overcast" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
"Partly cloudy" { return "⛅️partly cloudy" }
|
|
|
|
|
"Patchy light rain" { return "💧 patchy light rain" }
|
|
|
|
|
"Patchy rain possible" { return "💧 patchy rain possible" }
|
2022-12-04 10:40:18 +01:00
|
|
|
|
"Sunny" { return "☀️ sunny" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
"Thundery outbreaks possible" { return "⚡️thundery outbreaks possible" }
|
2022-12-04 10:40:18 +01:00
|
|
|
|
default { return "$Text" }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetWindDir { param([string]$Text)
|
|
|
|
|
switch($Text) {
|
|
|
|
|
"NW" { return "↘" }
|
|
|
|
|
"NNW" { return "↓" }
|
|
|
|
|
"N" { return "↓" }
|
|
|
|
|
"NNE" { return "↓" }
|
|
|
|
|
"NE" { return "↙" }
|
|
|
|
|
"ENE" { return "←" }
|
|
|
|
|
"E" { return "←" }
|
|
|
|
|
"ESE" { return "←" }
|
|
|
|
|
"SE" { return "↖" }
|
|
|
|
|
"SSE" { return "↑" }
|
|
|
|
|
"S" { return "↑" }
|
|
|
|
|
"SSW" { return "↑" }
|
|
|
|
|
"SW" { return "↗" }
|
|
|
|
|
"WSW" { return "→" }
|
|
|
|
|
"W" { return "→" }
|
|
|
|
|
"WNW" { return "→" }
|
|
|
|
|
default { return "$Text" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$Weather = (Invoke-WebRequest -URI http://wttr.in/${Location}?format=j1 -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
|
|
|
|
|
$Area = $Weather.nearest_area.areaName.value
|
|
|
|
|
$Region = $Weather.nearest_area.region.value
|
|
|
|
|
$Country = $Weather.nearest_area.country.value
|
|
|
|
|
[int]$Day = 0
|
|
|
|
|
foreach($Hourly in $Weather.weather.hourly) {
|
|
|
|
|
$Hour = $Hourly.time / 100
|
2022-12-04 10:40:18 +01:00
|
|
|
|
$Temp = $(($Hourly.tempC.toString()).PadLeft(3))
|
2022-11-17 20:02:26 +01:00
|
|
|
|
$Precip = $Hourly.precipMM
|
2022-12-04 10:40:18 +01:00
|
|
|
|
$Humidity = $(($Hourly.humidity.toString()).PadLeft(3))
|
2022-11-17 20:02:26 +01:00
|
|
|
|
$Pressure = $Hourly.pressure
|
2022-12-04 10:40:18 +01:00
|
|
|
|
$WindSpeed = $(($Hourly.windspeedKmph.toString()).PadLeft(2))
|
|
|
|
|
$WindDir = GetWindDir $Hourly.winddir16Point
|
2022-11-17 20:02:26 +01:00
|
|
|
|
$UV = $Hourly.uvIndex
|
2022-12-04 10:40:18 +01:00
|
|
|
|
$Clouds = $(($Hourly.cloudcover.toString()).PadLeft(3))
|
|
|
|
|
$Visib = $(($Hourly.visibility.toString()).PadLeft(2))
|
|
|
|
|
$Desc = GetDescription $Hourly.weatherDesc.value
|
2022-11-17 20:02:26 +01:00
|
|
|
|
if ($Hour -eq 0) {
|
|
|
|
|
if ($Day -eq 0) {
|
2022-12-04 10:40:18 +01:00
|
|
|
|
Write-Host -foregroundColor green "TODAY 🌡°C ☂️mm 💧 💨km/h ☀️UV ☁️ 👁km at $Area ($Region, $Country)"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
} elseif ($Day -eq 1) {
|
2022-12-04 10:40:18 +01:00
|
|
|
|
Write-Host -foregroundColor green "TOMORROW"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
} else {
|
|
|
|
|
Write-Host -foregroundColor green "Day after tomorrow"
|
|
|
|
|
}
|
|
|
|
|
$Day++
|
|
|
|
|
}
|
2022-12-04 10:40:18 +01:00
|
|
|
|
"$(($Hour.toString()).PadLeft(2))°° $Temp° $Precip $Humidity% $($WindDir)$WindSpeed $UV $Clouds% $Visib $Desc"
|
2022-11-17 20:02:26 +01:00
|
|
|
|
}
|
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
2021-11-08 21:36:42 +01:00
|
|
|
|
*Generated by convert-ps2md.ps1 using the comment-based help of list-weather.ps1*
|