Last active
July 21, 2016 20:36
-
-
Save gerane/41c80fb05e816b28fd52fddd2a3c3669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-WeatherEmoji | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[string[]]$Condition, | |
[Boolean]$DayTime | |
) | |
Process | |
{ | |
# π© | |
if ($Daytime -eq $true) | |
{ | |
$Clear = 'β' | |
$ClearColor = 'Yellow' | |
} | |
else | |
{ | |
$Clear = 'π' | |
$ClearColor = 'White' | |
} | |
Switch ($Condition) | |
{ | |
'Chance of Flurries' { (Write-Host '?π¨' -ForegroundColor White -NoNewline) } | |
'Chance of Rain' { (Write-Host '?π§' -ForegroundColor Cyan -NoNewline) } | |
'Chance Rain' { (Write-Host '?π§' -ForegroundColor Cyan -NoNewline) } | |
'Chance of Freezing Rain' { (Write-Host '?π¨' -ForegroundColor White -NoNewline) } | |
'Chance of Sleet' { (Write-Host '?π¨' -ForegroundColor White -NoNewline) } | |
'Chance of Snow' { (Write-Host '?β' -ForegroundColor White -NoNewline) } | |
'Chance of Thunderstorms' { (Write-Host '?β‘' -ForegroundColor Yellow -NoNewline) } | |
'Chance of a Thunderstorm' { (Write-Host '?β‘' -ForegroundColor Yellow -NoNewline) } | |
'Clear' { (Write-Host $Clear -ForegroundColor $ClearColor -NoNewline) } | |
'Cloudy' { (Write-Host 'β' -ForegroundColor Gray -NoNewline) } | |
'Flurries' { (Write-Host 'π¨' -ForegroundColor White -NoNewline) } | |
'Fog' { (Write-Host 'π«'-ForegroundColor Gray -NoNewline) } | |
'Haze' { (Write-Host 'π«'-ForegroundColor Gray -NoNewline) } | |
'Mostly Cloudy' { (Write-Host 'β ' -ForegroundColor Gray -NoNewline) } | |
'Mostly Sunny' { (Write-Host 'π€' -ForegroundColor Yellow -NoNewline) } | |
'Partly Cloudy' { (Write-Host 'π€' -ForegroundColor Gray -NoNewline) } | |
'Partly Sunny' { (Write-Host 'β ' -ForegroundColor DarkYellow -NoNewline) } | |
'Freezing Rain' { (Write-Host 'π¨' -ForegroundColor White -NoNewline) } | |
'Rain' { (Write-Host 'π§' -ForegroundColor Cyan -NoNewline) } | |
'Sleet' { (Write-Host 'π¨' -ForegroundColor White -NoNewline) } | |
'Snow' { (Write-Host 'β' -ForegroundColor White -NoNewline) } | |
'Sunny' { (Write-Host 'β' -ForegroundColor Yellow -NoNewline) } | |
'Thunderstorms' { (Write-Host 'β‘' -ForegroundColor Yellow -NoNewline) } | |
'Thunderstorm' { (Write-Host 'β‘' -ForegroundColor Yellow -NoNewline) } | |
'Unknown' { (Write-Host '?' -ForegroundColor White -NoNewline) } | |
'Overcast' { (Write-Host 'β' -ForegroundColor Gray -NoNewline) } | |
'Scattered Clouds' { (Write-Host 'β' -ForegroundColor Gray -NoNewline) } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Get Weather | |
$Base = 'http://api.wunderground.com/api/' | |
$ApiKey = 'YOURAPIKEY' | |
$Header = 'application/json' | |
$Uri = $Base + $ApiKey + "/astronomy/forecast/hourly/alerts/conditions/q/autoip.json" | |
$Weather = Invoke-RestMethod -Uri $Uri -ContentType $Header | |
$Condition = $Weather.hourly_forecast[0].condition | |
$Temp = $Weather.current_observation.temp_f | |
$CurrentTime = $Weather.moon_phase.current_time.hour | |
$SunriseTime = $Weather.moon_phase.sunrise.hour | |
$SunsetTime = $Weather.moon_phase.sunset.hour | |
$Alert = $Weather.alerts | |
if ($CurrentTime -ge $SunriseTime -OR $CurrentTime -lt $SunsetTime) | |
{ | |
$DayTime = $True | |
} | |
else | |
{ | |
$DayTime = $False | |
} | |
Write-Host "Weather: " -NoNewline -ForegroundColor White | |
Write-Host "$Condition " -ForegroundColor Cyan -NoNewline | |
Get-WeatherEmoji -Condition $Condition -DayTime $DayTime | |
Write-Host " $TempΒ°F" -ForegroundColor Cyan | |
if ($Alert -ne $null) | |
{ | |
$Env:WeatherAlert = $Alert | |
switch ($Alert.type) | |
{ | |
'HUR' { $AlertType = 'Hurricane Local Statement' } | |
'TOR' { $AlertType = 'Tornado Warning' } | |
'TOW' { $AlertType = 'Tornado Watch' } | |
'WRN' { $AlertType = 'Severe Thunderstorm Warning' } | |
'SEW' { $AlertType = 'Severe Thunderstorm Watch' } | |
'WIN' { $AlertType = 'Winter Weather Advisory' } | |
'FLO' { $AlertType = 'Flood Warning' } | |
'WAT' { $AlertType = 'Flood Watch / Statement' } | |
'WND' { $AlertType = 'High Wind Advisory' } | |
'SVR' { $AlertType = 'Severe Weather Statement' } | |
'HEA' { $AlertType = 'Heat Advisory' } | |
'FOG' { $AlertType = 'Dense Fog Advisory' } | |
'SPE' { $AlertType = 'Special Weather Statement' } | |
'FIR' { $AlertType = 'Fire Weather Advisory' } | |
'VOL' { $AlertType = 'Volcanic Activity Statement' } | |
'HWW' { $AlertType = 'Hurricane Wind Warning' } | |
'REC' { $AlertType = 'Record Set' } | |
'REP' { $AlertType = 'Public Reports' } | |
'PUB' { $AlertType = 'Public Information Statement' } | |
} | |
Write-Host "[ALERT] $($AlertType): For more information see `$Env:WeatherAlert" -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
π