PowerShell/Scripts/check-wind.ps1

31 lines
995 B
PowerShell
Raw Normal View History

2021-12-13 11:11:45 +01:00
<#
.SYNOPSIS
Checks the wind conditions
.DESCRIPTION
2022-01-29 12:47:46 +01:00
This PowerShell script determines the current wind conditions and replies by text-to-speech (TTS).
2021-12-13 11:11:45 +01:00
.PARAMETER location
Specifies the location to use (determined automatically per default)
.EXAMPLE
2023-08-06 21:35:36 +02:00
PS> ./check-wind.ps1
2021-12-13 11:11:45 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2021-12-13 11:11:45 +01:00
#>
param([string]$location = "") # empty means determine automatically
try {
$Weather = (Invoke-WebRequest http://wttr.in/${location}?format=j1 -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
$WindSpeed = $Weather.current_condition.windspeedKmph
$WindDir = $Weather.current_condition.winddir16Point
$Area = $Weather.nearest_area.areaName.value
$Region = $Weather.nearest_area.region.value
2022-11-18 16:54:04 +01:00
& "$PSScriptRoot/speak-english.ps1" "$($WindSpeed)km/h wind from $WindDir at $Area ($Region)."
2021-12-13 11:11:45 +01:00
exit 0 # success
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-12-13 11:11:45 +01:00
exit 1
}