Skip to content

Instantly share code, notes, and snippets.

@gerane
Last active July 21, 2016 20:36
Show Gist options
  • Save gerane/41c80fb05e816b28fd52fddd2a3c3669 to your computer and use it in GitHub Desktop.
Save gerane/41c80fb05e816b28fd52fddd2a3c3669 to your computer and use it in GitHub Desktop.
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) }
}
}
}
## 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
}
@michaeltlombardi
Copy link

πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment