Skip to content

Instantly share code, notes, and snippets.

@mconnell
Created April 13, 2011 08:42
Show Gist options
  • Save mconnell/917205 to your computer and use it in GitHub Desktop.
Save mconnell/917205 to your computer and use it in GitHub Desktop.
function Weather(locationName){
var locationURL = "http://www.google.com/ig/api?weather="+locationName;
var forcast = {};
$.get(locationURL, function(data){
var current = $(data).find('current_conditions');
['condition', 'temp_f', 'temp_c', 'humidity', 'wind_condition'].forEach(function(attribute){
forcast[attribute] = $(current).find(attribute).attr('data');
});
});
return forcast;
};
// Weather('Edinburgh');
// Object
// condition: "Partly Cloudy"
// humidity: "Humidity: 76%"
// temp_c: "8"
// temp_f: "46"
// wind_condition: "Wind: SW at 14 mph"
// __proto__: Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment