Last active
August 29, 2015 14:26
-
-
Save afaulkinberry/65f361bca89cc491d302 to your computer and use it in GitHub Desktop.
AngularJS - http connection to Yahoo weather
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
//Query Yahoo weather | |
app.factory('openweather', function($http, $q) { | |
return { | |
getWeather: function(zip) { | |
return $http({ | |
method: 'GET', | |
url: 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22' + zip + '%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys', | |
}).then( | |
function(data){ return data; }, | |
function(error){ return error; } | |
); | |
} | |
}; | |
}); |
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 fetchWeather(zip) { | |
openweather.getWeather(zip).then( | |
function(data){ | |
$scope.weatherData = data.data.query.results.channel; | |
$scope.weatherDays = $scope.weatherData.item.forecast; | |
var desc = $scope.weatherData.item.description.split("\"/><br", 2); | |
$scope.weatherPic = desc[0].replace("\n<img src=\"", ""); | |
}, | |
function(data){ return; } | |
); | |
} |
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
{ | |
"query":{ | |
"count":1, | |
"created":"2015-07-30T20:58:21Z", | |
"lang":"en-us", | |
"results":{ | |
"channel":{ | |
"title":"Yahoo! Weather - Boston, MA", | |
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Boston__MA/*http://weather.yahoo.com/forecast/USMA0522_f.html", | |
"description":"Yahoo! Weather for Boston, MA", | |
"language":"en-us", | |
"lastBuildDate":"Thu, 30 Jul 2015 3:52 pm EDT", | |
"ttl":"60", | |
"location":{ | |
"city":"Boston", | |
"country":"United States", | |
"region":"MA" | |
}, | |
"units":{ | |
"distance":"mi", | |
"pressure":"in", | |
"speed":"mph", | |
"temperature":"F" | |
}, | |
"wind":{ | |
"chill":"89", | |
"direction":"230", | |
"speed":"22" | |
}, | |
"atmosphere":{ | |
"humidity":"55", | |
"pressure":"29.76", | |
"rising":"2", | |
"visibility":"10" | |
}, | |
"astronomy":{ | |
"sunrise":"5:33 am", | |
"sunset":"8:04 pm" | |
}, | |
"image":{ | |
"title":"Yahoo! Weather", | |
"width":"142", | |
"height":"18"," | |
link":"http://weather.yahoo.com", | |
"url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif" | |
}, | |
"item":{ | |
"title":"Conditions for Boston, MA at 3:52 pm EDT", | |
"lat":"42.37", | |
"long":"-71.02", | |
"link":"http://us.rd.yahoo.com/dailynews/rss/weather/Boston__MA/*http://weather.yahoo.com/forecast/USMA0522_f.html", | |
"pubDate":"Thu, 30 Jul 2015 3:52 pm EDT", | |
"condition":{ | |
"code":"28", | |
"date":"Thu, 30 Jul 2015 3:52 pm EDT", | |
"temp":"89", | |
"text":"Mostly Cloudy" | |
}, | |
"description":"\n<img src=\"http://l.yimg.com/a/i/us/we/52/28.gif\"/><br />\n<b>Current Conditions:</b><br />\nMostly Cloudy, 89 F<BR />\n<BR /><b>Forecast:</b><BR />\nThu - Thunderstorms Early. High: 91 Low: 69<br />\nFri - Sunny. High: 88 Low: 68<br />\nSat - Mostly Sunny. High: 86 Low: 68<br />\nSun - Mostly Sunny. High: 86 Low: 69<br />\nMon - Mostly Sunny. High: 87 Low: 71<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Boston__MA/*http://weather.yahoo.com/forecast/USMA0522_f.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n", | |
"forecast":[ | |
{ | |
"code":"47", | |
"date":"30 Jul 2015", | |
"day":"Thu", | |
"high":"91", | |
"low":"69", | |
"text":"Thunderstorms Early" | |
}, | |
{ | |
"code":"32", | |
"date":"31 Jul 2015", | |
"day":"Fri", | |
"high":"88", | |
"low":"68", | |
"text":"Sunny" | |
}, | |
{ | |
"code":"34", | |
"date":"1 Aug 2015", | |
"day":"Sat", | |
"high":"86", | |
"low":"68", | |
"text":"Mostly Sunny" | |
}, | |
{ | |
"code":"34", | |
"date":"2 Aug 2015", | |
"day":"Sun", | |
"high":"86", | |
"low":"69", | |
"text":"Mostly Sunny" | |
}, | |
{ | |
"code":"34", | |
"date":"3 Aug 2015", | |
"day":"Mon", | |
"high":"87", | |
"low":"71", | |
"text":"Mostly Sunny" | |
} | |
], | |
"guid":{ | |
"isPermaLink":"false", | |
"content":"USMA0522_2015_08_03_7_00_EDT" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment