Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Created May 6, 2016 15:52
Show Gist options
  • Save 1RedOne/8f6d64b53f21bb695bde57124f368e43 to your computer and use it in GitHub Desktop.
Save 1RedOne/8f6d64b53f21bb695bde57124f368e43 to your computer and use it in GitHub Desktop.
Get-Weather
Function Get-Weather {
$city = "33.9533,-84.5406"
#sign up for an API key here https://developer.forecast.io/
$APIkey = "$null"
$url = "https://api.forecast.io/forecast/$APIkey/$city"
try{$weather = Invoke-WebRequest $url -ea STOP|ConvertFrom-Json }
catch{write-host -ForegroundColor Yellow "We don't seem to have internet access"
break}
$ForeCastTime = [TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($weather.currently.time))
("The weather is generally " + $weather.currently.summary + " and currently " + $weather.currently.temperature + " degrees Fahrenheit at " + $ForeCastTime.DateTime)
("wind is gusting up to " + $weather.currently.windspeed + " m/PH with a chance of precipitation at " + $weather.currently.precipProbability)
#it is currently 54.9 degrees Fahrenheit at Monday, October 20, 2014 10:23:11 AM
("The weekly forecast is " + (($weather.daily.summary) -creplace '\?',"").ToLower())
#return a Global weather object for us to play with
$Global:weather = $weather
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment