|
$dependencies = @( |
|
"Get-GeoLocationCoordinates", |
|
"Get-GeoCodeCoordinatesAddress", |
|
"Get-GeoCoordinatesSunriseAndSunset", |
|
"Get-wttrWeatherReport", |
|
) |
|
foreach ($script in ){ |
|
iex ((New-Object System.Net.WebClient).DownloadString("https://gist.githubusercontent.com/Gravifer/a0012ea5f115bf48bc652c1b02845bd8/raw/d6d06a82ed8282e14aed0f258ff39b8e89dcf01e/$script.ps1")) |
|
} |
|
|
|
function Write-LocalWeather{ |
|
[CmdletBinding()] |
|
param ( |
|
[System.DateTime] $now = (Get-Date), |
|
[Parameter(ValueFromPipeline=$true)] |
|
[System.Object] $loc = (Get-GeoLocationCoordinates -l), |
|
[Switch] $Fast |
|
) |
|
# $using_wego = $false |
|
$weatherbrief = try { |
|
$addr = try { |
|
$addr = (Get-GeoCodeCoordinatesAddress $loc) |
|
if ((-not $addr.confidence) -or ($addr.confidence -ge 0.5)) { |
|
if (($addr.poi.name) -or ($addr.osmtags.name) -or ($addr.city)){ |
|
@($addr.poi.name, $addr.osmtags.name, $addr.city) | Join-String -Separator " " |
|
} elseif ($addr.standard.confidence -ge 0.5) { |
|
@($addr.standard.addresst, $addr.standard.city) | Join-String -Separator " " |
|
} else { |
|
throw (New-Object System.Exception "Cannot find address") |
|
"$([math]::round(($loc).Longitude,3)),$([math]::round(($loc).Latitude,3))" |
|
} |
|
} else { |
|
throw (New-Object System.Exception "Cannot find address") |
|
"$([math]::round(($loc).Longitude,3)),$([math]::round(($loc).Latitude,3))" |
|
} |
|
} catch { Write-Progress " (Address unavailable)" -Status "($loc) $addr" -PercentComplete 100 #-NoNewline -ForegroundColor DarkGray; |
|
"$([math]::round(($loc).Longitude,3)),$([math]::round(($loc).Latitude,3))" } |
|
if ($fast) {Get-wttrWeatherReport -Location $loc -Format "$moonphase%c π‘οΈ%t (%f π¦%h π¬οΈ%w) π§%p π¨%P" # -ErrorAction SilentlyContinue |
|
} else { |
|
$test_request = ((Get-wttrWeatherReport -Location $loc -Format "%x %t %f %h %w %p %P %c %m") -split '\s+') |
|
$moonphase = try { |
|
$suntimes = (Get-GeoCoordinatesSunriseAndSunset ($loc).Latitude ($loc).Longitude); |
|
$sunrise = $suntimes.Sunrise; $sunset = $suntimes.Sunset; |
|
$nodaylight = (($now -le $sunrise) -or ($now -ge $sunset)) |
|
if ($nodaylight) {$test_request[8]} |
|
} catch { Write-Progress " (Daylight unavailable)" -PercentComplete 100 } # -NoNewline -ForegroundColor DarkGray } |
|
$weather = "$moonphase$(if ((-not $nodaylight) -or ($test_request[0] -ne "o")) {$test_request[7]})" |
|
$precipitation = if (($test_request[0] -match "[/\.x\*\?]") -or |
|
([double]($test_request[5] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+") -gt 0)) {$test_request[5]} |
|
# write-host "percipitation$precipitation $($test_request[0] -match "[/\.x\*\?]") $([double]($test_request[1] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+"))" |
|
} |
|
} catch { |
|
# Write-Progress is a bit of a performance hog. You might reconsider. |
|
Write-Progress " $_" -PercentComplete 100 |
|
Write-Host " (Weather unavailable)" -NoNewline -ForegroundColor DarkGray |
|
# $using_wego = $true |
|
}; Write-Host |
|
Write-Host "$($addr): " -NoNewline -ForegroundColor Yellow |
|
if ($false) {wego 4 "$((geo).Latitude),$((geo).Longitude)" |
|
} else { |
|
if ($fast) {Write-Host $weatherbrief -NoNewline} else { |
|
if ($test_request) {Write-Host "$weather$precipitation " -NoNewline |
|
# Switch is nice and compressed, but since it won't have to deal with executing the script block, `if` will be faster. |
|
# Style: You might consider that the only difference between the commands which follow only differ by the start of the message and the colour. |
|
switch ([double]($test_request[1] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+")) { |
|
{($_ -ge 22) -and ($_ -le 25)} { |
|
Write-Host "π‘οΈ$($test_request[1])" -NoNewline -ForegroundColor Green} |
|
{(($_ -ge 20) -and ($_ -lt 22)) -or (($_ -gt 25) -and ($_ -le 28))} { |
|
Write-Host "π‘οΈ$($test_request[1]) " -NoNewline} |
|
{($_ -ge 5) -and ($_ -lt 20)} { |
|
Write-Host "π‘οΈ$($test_request[1]) " -NoNewline -ForegroundColor Cyan} |
|
{($_ -ge -10) -and ($_ -lt 5)} { |
|
Write-Host "π‘οΈ$($test_request[1]) " -NoNewline -ForegroundColor Blue} |
|
{($_ -lt -10)} { |
|
Write-Host "π₯Ά$($test_request[1])" -NoNewline -ForegroundColor DarkBlue} |
|
{($_ -gt 28) -and ($_ -le 34)} { |
|
Write-Host "π‘οΈ$($test_request[1])" -NoNewline -ForegroundColor Yellow} |
|
{($_ -gt 34) -and ($_ -le 40)} { |
|
Write-Host "π₯΅$($test_request[1])" -NoNewline -ForegroundColor Red} |
|
{($_ -gt 40)} { |
|
Write-Host "π₯$($test_request[1])" -NoNewline -ForegroundColor Magenta} |
|
} |
|
Write-Host "(" -NoNewline |
|
if ($test_request[1] -ne $test_request[2]){ |
|
switch ([double]($test_request[2] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+")) { |
|
{($_ -ge 22) -and ($_ -le 25)} { |
|
Write-Host "$($test_request[2]) " -NoNewline -ForegroundColor Green} |
|
{(($_ -ge 20) -and ($_ -lt 22)) -or (($_ -gt 25) -and ($_ -le 28))} { |
|
Write-Host "$($test_request[2]) " -NoNewline} |
|
{($_ -ge 5) -and ($_ -lt 20)} { |
|
Write-Host "$($test_request[2]) " -NoNewline -ForegroundColor Cyan} |
|
{($_ -ge -10) -and ($_ -lt 5)} { |
|
Write-Host "$($test_request[2]) " -NoNewline -ForegroundColor Blue} |
|
{($_ -lt -10)} { |
|
Write-Host "$($test_request[2])" -NoNewline -ForegroundColor DarkBlue} |
|
{($_ -gt 28) -and ($_ -le 32)} { |
|
Write-Host "$($test_request[2]) " -NoNewline -ForegroundColor Yellow} |
|
{($_ -gt 32) -and ($_ -le 40)} { |
|
Write-Host "$($test_request[2])" -NoNewline -ForegroundColor Red} |
|
{($_ -gt 40)} { |
|
Write-Host "$($test_request[2])" -NoNewline -ForegroundColor Magenta} |
|
}} |
|
switch ([double]($test_request[3] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+")) { |
|
{($_ -ge 50) -and ($_ -le 60)} { |
|
Write-Host "π§$($test_request[3])" -NoNewline -ForegroundColor Green} |
|
{(($_ -ge 40) -and ($_ -lt 50)) -or (($_ -gt 60) -and ($_ -le 70))} { |
|
Write-Host "π§$($test_request[3])" -NoNewline} |
|
{($_ -gt 70) -and ($_ -le 100)} { |
|
Write-Host "π¦$($test_request[3])" -NoNewline -ForegroundColor Cyan} |
|
{($_ -gt 100)} { |
|
Write-Host "π¦$($test_request[3])" -NoNewline -ForegroundColor Blue} |
|
{($_ -ge 20) -and ($_ -lt 40)} { |
|
Write-Host "ποΈ$($test_request[3])" -NoNewline -ForegroundColor Yellow} |
|
{($_ -lt 20)} { |
|
Write-Host "πͺ$($test_request[3])" -NoNewline -ForegroundColor DarkYellow} |
|
} |
|
switch ([double]($test_request[4] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+")) { |
|
{($_ -gt 0) -and ($_ -le 2)} { |
|
Write-Host " π$($test_request[4])" -NoNewline -ForegroundColor DarkGray -Separator ""} |
|
{($_ -gt 2) -and ($_ -le 6)} { |
|
Write-Host " π$($test_request[4])" -NoNewline -ForegroundColor Gray -Separator ""} |
|
{($_ -gt 6) -and ($_ -le 19)} { |
|
Write-Host " π¬οΈ$($test_request[4])" -NoNewline -ForegroundColor Yellow -Separator ""} |
|
{($_ -gt 19) -and ($_ -le 40)} { |
|
Write-Host " π¬οΈ$($test_request[4])" -NoNewline -ForegroundColor Cyan -Separator ""} |
|
{($_ -gt 40) -and ($_ -le 55)} { |
|
Write-Host " π¬οΈ$($test_request[4])" -NoNewline -ForegroundColor Blue -Separator ""} |
|
{($_ -gt 55) -and ($_ -le 75)} { |
|
Write-Host " π¬οΈ$($test_request[4])" -NoNewline -ForegroundColor DarkBlue -Separator ""} |
|
{($_ -gt 75) -and ($_ -le 100)} { |
|
Write-Host " πͺοΈ$($test_request[4])" -NoNewline -ForegroundColor Red -Separator ""} |
|
{($_ -gt 100)} { |
|
Write-Host " π$($test_request[4])" -NoNewline -ForegroundColor Magenta -Separator ""} |
|
}; Write-Host "`b) " -NoNewline |
|
switch ([double]($test_request[6] -replace "[^\+\-\d.]" -replace "(?<=\d+\.\d+)\D+")) { |
|
{($_ -gt 1010) -and ($_ -le 1020)} { |
|
Write-Host "π¨$($test_request[6]) " -NoNewline -ForegroundColor Green} |
|
{(($_ -ge 1005.7) -and ($_ -lt 1010)) -or (($_ -gt 1020) -and ($_ -le 1026))} { |
|
Write-Host "π¨$($test_request[6]) " -NoNewline} |
|
{($_ -ge 1000) -and ($_ -le 1005.7)} { |
|
Write-Host "π¨$($test_request[6]) " -NoNewline -ForegroundColor Cyan} |
|
{($_ -lt 1000)} { |
|
Write-Host "π¨$($test_request[6]) " -NoNewline -ForegroundColor Blue} |
|
{($_ -gt 1026)} { |
|
Write-Host "π¨$($test_request[6]) " -NoNewline -ForegroundColor Yellow} |
|
} |
|
} |
|
} |
|
} |
|
Write-Host "[$(Get-Date -Format (Get-Culture).DateTimeFormat.FullDateTimePattern)]`n" -ForegroundColor Cyan |
|
} |
|
Set-Alias -Name weather -Value Write-LocalWeather |