We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wanna get 7-day weather forcast data from Yahoo weather. I tried a thousand times but it simply does' t work. I cannot even make it with the following code. Could somebody help me with that? I appreciate it so much. I am using Processing 3.2.1 and windows 10.
void setup(){
XML xml = loadXML("https:"+"//query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D4177");
XML yweather = xml.getChild("channel/item/yweather:condition");
int weatherCondition = yweather.getInt("code");
// Print the results
println(weatherCondition);
}
I tried example code from processing.org and it did work.
// The following short XML file called "mammals.xml" is parsed
// in the code below. It must be in the project's "data" folder.
//
// <?xml version="1.0"?>
// <mammals>
// <animal id="0" species="Capra hircus">Goat</animal>
// <animal id="1" species="Panthera pardus">Leopard</animal>
// <animal id="2" species="Equus zebra">Zebra</animal>
// </mammals>
XML xml;
void setup() {
xml = loadXML("mammals.xml");
XML[] children = xml.getChildren("animal");
for (int i = 0; i < children.length; i++) {
int id = children[i].getInt("id");
String coloring = children[i].getString("species");
String name = children[i].getContent();
println(id + ", " + coloring + ", " + name);
}
}
// Sketch prints:
// 0, Capra hircus, Goat
// 1, Panthera pardus, Leopard
// 2, Equus zebra, Zebra
And then I saved the weather data as xml file and load it in Processing. It still says Null Pointer Exception. Also I tried Yahoo Weather Library from com.onformative.yahooweather. But it doen' t have 7-day forcast. Thanks for your help!
Answers
Edit post, highlight code, press ctrl-o
Perhaps check out https://github.com/processing/processing/files/231534/XMLYahooWeather3.zip
if you just hit the link in a bowser...
https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid=4177
you'll see the returned xml looks like
there's an extra 'results' in there. so you want
and not
Thanks!