Skip to content

Commit ddd14e8

Browse files
committed
fixes xml yahoo weather example to use WOEID now processing#429
1 parent 2d16887 commit ddd14e8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

content/examples/Topics/Advanced Data/XMLYahooWeather/XMLYahooWeather.pde

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ int temperature = 0;
1111
// We're going to store text about the weather
1212
String weather = "";
1313

14-
// The zip code we'll check for
14+
15+
// Yahoo weather uses something called A WOEID (Where On Earth IDentifier)
16+
// https://en.wikipedia.org/wiki/WOEID
17+
// This is the WOEID for zip code 10003
1518
String zip = "10003";
19+
String woeid = "12761335";
1620

1721
PFont font;
1822

@@ -23,13 +27,13 @@ void setup() {
2327
textFont(font);
2428

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

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

3135
// Grab the element we want
32-
XML forecast = xml.getChild("channel/item/yweather:forecast");
36+
XML forecast = xml.getChild("results/channel/item/yweather:forecast");
3337

3438
// Get the attributes we want
3539
temperature = forecast.getInt("high");
@@ -41,8 +45,8 @@ void draw() {
4145
fill(0);
4246

4347
// Display all the stuff we want to display
44-
text("Zip code: " + zip, width*0.15, height*0.33);
45-
text("Today’s high: " + temperature, width*0.15, height*0.5);
48+
text("Zip: " + zip, width*0.15, height*0.33);
49+
text("Today’s high: " + temperature + "°F", width*0.15, height*0.5);
4650
text("Forecast: " + weather, width*0.15, height*0.66);
4751

48-
}
52+
}

0 commit comments

Comments
 (0)