2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
. SYNOPSIS
2021-12-01 12:53:37 +01:00
Checks the weather
2021-10-04 21:29:23 +02:00
. DESCRIPTION
2022-01-29 12:47:46 +01:00
This PowerShell script checks the current weather report .
2021-10-16 16:50:10 +02:00
. PARAMETER location
Specifies the location to use ( determined automatically per default )
2021-07-13 21:10:02 +02:00
. EXAMPLE
2021-09-24 17:19:49 +02:00
PS > . / check-weather
2021-07-13 21:10:02 +02:00
. LINK
https : / / github . com / fleschutz / PowerShell
. NOTES
2022-01-29 12:47:46 +01:00
Author : Markus Fleschutz / License : CC0
2021-04-19 19:20:49 +02:00
#>
2021-09-24 17:19:49 +02:00
param ( [ string ] $location = " " ) # empty means determine automatically
2021-04-19 19:20:49 +02:00
try {
2021-12-02 15:39:50 +01:00
$Weather = ( Invoke-WebRequest http : / / wttr . in / $ { location } ? format = j1 -userAgent " curl " -useBasicParsing ) . Content | ConvertFrom-Json
2021-04-19 19:20:49 +02:00
$Temp = $Weather . current_condition . temp_C
$Precip = $Weather . current_condition . precipMM
$Humidity = $Weather . current_condition . humidity
$Pressure = $Weather . current_condition . pressure
$WindSpeed = $Weather . current_condition . windspeedKmph
$WindDir = $Weather . current_condition . winddir16Point
$UV = $Weather . current_condition . uvIndex
$Visib = $Weather . current_condition . visibility
$Clouds = $Weather . current_condition . cloudcover
$Desc = $Weather . current_condition . weatherDesc . value
$Area = $Weather . nearest_area . areaName . value
$Region = $Weather . nearest_area . region . value
2021-12-06 17:00:49 +01:00
& " $PSScriptRoot /give-reply.ps1 " " $( $Temp ) °C, $( $Precip ) mm rain, $( $Humidity ) % humidity, $( $WindSpeed ) km/h wind from $WindDir with $( $Clouds ) % clouds and $( $Visib ) km visibility at $Area ( $Region ). "
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-04-19 19:20:49 +02:00
} catch {
2022-04-13 12:06:32 +02:00
" ⚠️ Error in line $( $_ . InvocationInfo . ScriptLineNumber ) : $( $Error [ 0 ] ) "
2021-04-19 19:20:49 +02:00
exit 1
}