2024-11-08 12:38:20 +01:00
|
|
|
|
The *ping-weather.ps1* Script
|
|
|
|
|
===========================
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
|
|
This PowerShell script continuously shows the current weather conditions (similar to htop, 10 min update interval by default).
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Parameters
|
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
|
/home/markus/Repos/PowerShell/scripts/ping-weather.ps1 [[-Location] <String>] [[-UpdateInterval] <Int32>] [<CommonParameters>]
|
2022-11-17 19:46:02 +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
|
|
|
|
|
|
|
|
|
|
-UpdateInterval <Int32>
|
|
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
|
Position? 2
|
2023-05-26 12:20:18 +02:00
|
|
|
|
Default value 600
|
2022-11-17 19:46:02 +01:00
|
|
|
|
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.
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Example
|
|
|
|
|
-------
|
2022-11-17 19:46:02 +01:00
|
|
|
|
```powershell
|
2023-05-26 12:20:18 +02:00
|
|
|
|
PS> ./ping-weather
|
|
|
|
|
Current weather conditions at Paris (Ile-de-France), updating every 10 min...
|
|
|
|
|
🕗10:24 AM UTC 🌡23°C ☂️0.0mm 💨9km/h from S ☁️0% 💧41% ☀️UV6 1020hPa Sunny
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Notes
|
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Related Links
|
|
|
|
|
-------------
|
2022-11-17 19:46:02 +01:00
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
|
Script Content
|
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Ping the currrent weather conditions
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This PowerShell script continuously shows the current weather conditions (similar to htop, 10 min update interval by default).
|
|
|
|
|
.PARAMETER Location
|
|
|
|
|
Specifies the location to use (determined automatically per default)
|
|
|
|
|
.EXAMPLE
|
2023-05-26 12:20:18 +02:00
|
|
|
|
PS> ./ping-weather
|
|
|
|
|
Current weather conditions at Paris (Ile-de-France), updating every 10 min...
|
|
|
|
|
🕗10:24 AM UTC 🌡23°C ☂️0.0mm 💨9km/h from S ☁️0% 💧41% ☀️UV6 1020hPa Sunny
|
2022-11-17 20:02:26 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
2023-05-26 12:20:18 +02:00
|
|
|
|
param([string]$Location = "", [int]$UpdateInterval = 600)
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
|
|
try {
|
2023-05-26 12:20:18 +02:00
|
|
|
|
$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
|
|
|
|
|
"Current weather conditions at $Area ($Region), updating every $($UpdateInterval / 60) min..."
|
2022-11-17 20:02:26 +01:00
|
|
|
|
do {
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
|
$Description = $Weather.current_condition.WeatherDesc.value
|
|
|
|
|
$TempC = $Weather.current_condition.temp_C
|
|
|
|
|
$PrecipMM = $Weather.current_condition.precipMM
|
|
|
|
|
$WindSpeed = $Weather.current_condition.windspeedKmph
|
|
|
|
|
$WindDir = $Weather.current_condition.winddir16Point
|
|
|
|
|
$Clouds = $Weather.current_condition.cloudcover
|
|
|
|
|
$Humidity = $Weather.current_condition.humidity
|
|
|
|
|
$UV = $Weather.current_condition.uvIndex
|
|
|
|
|
$Visib = $Weather.current_condition.visibility
|
|
|
|
|
$Pressure = $Weather.current_condition.pressure
|
|
|
|
|
$Time = $Weather.current_condition.observation_time
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
|
|
"🕗$Time UTC 🌡$($TempC)°C ☂️$($PrecipMM)mm 💨$($WindSpeed)km/h from $WindDir ☁️$($Clouds)% 💧$($Humidity)% ☀️UV$UV 👀$($Visib)km $($Pressure)hPa $Description"
|
|
|
|
|
Start-Sleep -s $UpdateInterval
|
|
|
|
|
$Weather = (Invoke-WebRequest -URI http://wttr.in/${Location}?format=j1 -userAgent "curl" -useBasicParsing).Content | ConvertFrom-Json
|
2022-11-17 20:02:26 +01:00
|
|
|
|
} while ($true)
|
|
|
|
|
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
|
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:59)*
|