2022-11-18 17:02:20 +01:00
|
|
|
|
## The *list-weather.ps1* PowerShell Script
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
2022-02-10 09:01:07 +01:00
|
|
|
|
This PowerShell script lists the hourly weather report.
|
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
|
|
|
|
|
This PowerShell script lists the hourly weather report.
|
|
|
|
|
.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
|
|
|
|
|
|
|
|
|
|
function Describe { param([string]$Desc)
|
|
|
|
|
switch($Desc) {
|
|
|
|
|
"Clear" { return "🌙 clear " }
|
|
|
|
|
"Cloudy" { return "☁️ cloudy " }
|
|
|
|
|
"Light drizzle" { return "💧 light drizzle" }
|
2022-11-18 17:02:20 +01:00
|
|
|
|
"Light rain" { return "💧 light rain " }
|
|
|
|
|
"Light rain shower" { return "💧 light rain shower" }
|
2022-11-17 20:02:26 +01:00
|
|
|
|
"Mist" { return "🌫 misty " }
|
|
|
|
|
"Overcast" { return "☁️ overcast " }
|
|
|
|
|
"Partly cloudy" { return "⛅️partly cloudy" }
|
|
|
|
|
"Patchy light rain" { return "💧 patchy light rain" }
|
|
|
|
|
"Patchy rain possible" { return "💧 patchy rain possible" }
|
|
|
|
|
"Sunny" { return "☀️ sunny " }
|
|
|
|
|
"Thundery outbreaks possible" { return "⚡️thundery outbreaks possible" }
|
|
|
|
|
default { return "$Desc" }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
$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
|
|
|
|
|
if ($Hour -eq 0) {
|
|
|
|
|
if ($Day -eq 0) {
|
|
|
|
|
Write-Host -foregroundColor green "Today 🌡°C ☂️mm 💧 💨km/h from ☀️UV ☁️ at $Area ($Region, $Country)"
|
|
|
|
|
} elseif ($Day -eq 1) {
|
|
|
|
|
Write-Host -foregroundColor green "Tomorrow"
|
|
|
|
|
} else {
|
|
|
|
|
Write-Host -foregroundColor green "Day after tomorrow"
|
|
|
|
|
}
|
|
|
|
|
$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++
|
|
|
|
|
}
|
|
|
|
|
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*
|