Skip to content

Commit f5765c2

Browse files
committed
Merge pull request #201 from ybakos/200_XMLYahooWeather
XMLYahooWeather: Update for latest API
2 parents d7527d5 + f2c8b66 commit f5765c2

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Loading XML Data
3-
* by Daniel Shiffman.
4-
*
3+
* by Daniel Shiffman.
4+
*
55
* This example demonstrates how to use loadXML()
66
* to retrieve data from an XML document via a URL
77
*/
@@ -10,24 +10,35 @@
1010
int temperature = 0;
1111
// We're going to store text about the weather
1212
String weather = "";
13+
// We're going to store the location name
14+
String city = "";
1315

14-
// The zip code we'll check for
15-
String zip = "10003";
16+
// The woeid (where on earth id) we'll check for.
17+
// Search for "woeid lookup" to find your own.
18+
String woeid = "638242";
19+
20+
PFont font;
1621

1722
void setup() {
18-
size(200, 200);
23+
size(600, 360);
24+
25+
font = createFont("Merriweather-Light.ttf", 28);
26+
textFont(font);
1927

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

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

26-
// Grab the element we want
27-
XML forecast = xml.getChild("channel/item/yweather:forecast");
35+
// Grab the elements we want
36+
XML location = xml.getChild("results/channel/yweather:location");
37+
XML forecast = xml.getChild("results/channel/item/yweather:condition");
2838

2939
// Get the attributes we want
30-
temperature = forecast.getInt("high");
40+
city = location.getString("city");
41+
temperature = forecast.getInt("temp");
3142
weather = forecast.getString("text");
3243
}
3344

@@ -36,8 +47,8 @@ void draw() {
3647
fill(0);
3748

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

54+
}

0 commit comments

Comments
 (0)