Skip to content

Commit

Permalink
XMLYahooWeather: Update for latest API
Browse files Browse the repository at this point in the history
  • Loading branch information
Yong Bakos committed May 9, 2016
1 parent d7527d5 commit f2c8b66
Showing 1 changed file with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Loading XML Data
* by Daniel Shiffman.
*
* by Daniel Shiffman.
*
* This example demonstrates how to use loadXML()
* to retrieve data from an XML document via a URL
*/
Expand All @@ -10,24 +10,35 @@
int temperature = 0;
// We're going to store text about the weather
String weather = "";
// We're going to store the location name
String city = "";

// The zip code we'll check for
String zip = "10003";
// The woeid (where on earth id) we'll check for.
// Search for "woeid lookup" to find your own.
String woeid = "638242";

PFont font;

void setup() {
size(200, 200);
size(600, 360);

font = createFont("Merriweather-Light.ttf", 28);
textFont(font);

// The URL for the XML document
String url = "http://xml.weather.yahoo.com/forecastrss?p=" + zip;
String url = "http://query.yahooapis.com/v1/public/yql?format=xml&q=select+*+from+weather.forecast+where+woeid=" + woeid + "+and+u='C'";
println(url);

// Load the XML document
XML xml = loadXML(url);

// Grab the element we want
XML forecast = xml.getChild("channel/item/yweather:forecast");
// Grab the elements we want
XML location = xml.getChild("results/channel/yweather:location");
XML forecast = xml.getChild("results/channel/item/yweather:condition");

// Get the attributes we want
temperature = forecast.getInt("high");
city = location.getString("city");
temperature = forecast.getInt("temp");
weather = forecast.getString("text");
}

Expand All @@ -36,8 +47,8 @@ void draw() {
fill(0);

// Display all the stuff we want to display
text("Zip code: " + zip, 10, 50);
text("Today’s high: " + temperature, 10, 70);
text("Forecast: " + weather, 10, 90);
}
text("Location: " + city, width*0.15, height*0.33);
text("Today’s high: " + temperature, width*0.15, height*0.5);
text("Forecast: " + weather, width*0.15, height*0.66);

}

0 comments on commit f2c8b66

Please sign in to comment.