forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-weather.ps1
More file actions
executable file
·65 lines (62 loc) · 2.14 KB
/
Copy pathlist-weather.ps1
File metadata and controls
executable file
·65 lines (62 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
.SYNOPSIS
Lists the hourly 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" }
"Light rain shower" { return "💧light rain " }
"Mist" { return "🌫 misty " }
"Partly cloudy" { return "☁️bit cloudy " }
"Sunny" { return "☀️sunny " }
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
}