2024-10-01 15:11:03 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2024-11-25 09:44:07 +01:00
|
|
|
|
Lists the weather of cities
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.DESCRIPTION
|
2023-10-05 09:05:44 +02:00
|
|
|
|
This PowerShell script lists the current weather conditions of cities world-wide (west to east).
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-06 21:35:36 +02:00
|
|
|
|
PS> ./list-city-weather.ps1
|
2024-11-25 09:44:07 +01:00
|
|
|
|
|
|
|
|
|
CITY TEMP RAIN WIND SUN
|
|
|
|
|
---- ---- ---- ---- ---
|
|
|
|
|
Hawaii ⛅️ +25°C 0.0mm 69% ↙5km/h 06:49:15 → 17:47:57
|
|
|
|
|
...
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-29 12:47:46 +01:00
|
|
|
|
.NOTES
|
2022-04-26 15:36:21 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2020-12-29 15:14:21 +01:00
|
|
|
|
#>
|
2020-11-11 11:03:50 +01:00
|
|
|
|
|
2024-11-25 09:44:07 +01:00
|
|
|
|
function List-City-Weather {
|
|
|
|
|
$cities = @("Hawaii","Los Angeles","Mexico City","Dallas","Miami","New York","Rio de Janeiro","Paris","London","Berlin","Cape Town","Dubai","Mumbai","Singapore","Hong Kong","Perth","Peking","Tokyo","Sydney")
|
2024-11-22 14:57:21 +01:00
|
|
|
|
foreach($city in $cities) {
|
2024-11-25 09:44:07 +01:00
|
|
|
|
$icon = (Invoke-WebRequest http://wttr.in/${City}?format="%c" -UserAgent "curl" -useBasicParsing).Content
|
|
|
|
|
$temp = (Invoke-WebRequest http://wttr.in/${City}?format="%t" -UserAgent "curl" -useBasicParsing).Content
|
|
|
|
|
$rain = (Invoke-WebRequest http://wttr.in/${City}?format="%p %h" -UserAgent "curl" -useBasicParsing).Content
|
|
|
|
|
$wind = (Invoke-WebRequest http://wttr.in/${City}?format="%w" -UserAgent "curl" -useBasicParsing).Content
|
|
|
|
|
$sun = (Invoke-WebRequest http://wttr.in/${City}?format="%S → %s" -UserAgent "curl" -useBasicParsing).Content
|
|
|
|
|
New-Object PSObject -Property @{ CITY="$city $icon"; TEMP=$temp; RAIN=$rain; WIND=$wind; SUN=$sun }
|
2020-11-11 11:03:50 +01:00
|
|
|
|
}
|
2022-04-26 15:36:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2024-11-25 09:44:07 +01:00
|
|
|
|
List-City-Weather | Format-Table -property @{e='CITY';width=19},@{e='TEMP';width=9},@{e='RAIN';width=14},@{e='WIND';width=12},@{e='SUN';width=20}
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2020-12-09 10:30:55 +01:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2020-12-09 10:30:55 +01:00
|
|
|
|
exit 1
|
2023-10-05 09:05:44 +02:00
|
|
|
|
}
|