Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi,
I have some problem with this tutorial https://www.thingworx.com/wp-content/uploads/academic-program-predictive-weather-app-step-1-connect-to-yahoo.pdf.
When I call the GetYahooWeatherInformation service I get this error:
Code GetYahooWeatherInformation :
###############################################################
if(location!=null){
var test=location+" ";
var arrayLocations=test.split(",");
var lat=arrayLocations[0];
var long=arrayLocations[1];
var prm = {
url: "http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20geo.placefinder%20WHERE%20text%3D%22"+lat+","+long+"%22%20and%20gflags%3D%22R%22" /* STRING */,
timeout: 60 /* NUMBER */
};
// result: XML
var xmlPg = Resources["ContentLoaderFunctions"].LoadXML(prm);
var yahoo = new Namespace('http://www.yahooapis.com/v1/base.rng');
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(YahooWeatherFeed)
woeid =xmlPg.results.Result.woeid;
}
var params = {
url: "http://xml.weather.yahoo.com/forecastrss?w=" +woeid + "&u=f" /* STRING */,
timeout: 60 /* NUMBER */
};
// result: XML
var xmlPage = Resources["ContentLoaderFunctions"].LoadXML(params);
var yweather = new Namespace('http://xml.weather.yahoo.com/ns/rss/1.0');
var params = {
infoTableName : "InfoTable",
dataShapeName : "YahooWeatherFeed"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"),dataShapeName:STRING):INFOTABLE(YahooWeatherFeed)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
for each (var item in xmlPage.channel) {
var row = new Object()
row.Link = xmlPage.channel.item.link;
row.Title = xmlPage.channel.item.title;
row.WeatherCondition = "http://l.yimg.com/a/i/us/we/52/" +
xmlPage.channel.item.yweather::condition.@code + ".gif";
row.WeatherTemp = parseInt(xmlPage.channel.item.yweather::condition.@temp.toString());
row.WeatherHumidity = parseInt(xmlPage.channel.yweather::atmosphere.@humidity.toString());
row.WindSpeed = xmlPage.channel.yweather::wind.@speed.toString() + " " +
xmlPage.channel.yweather::units.@speed.toString();
row.WindDirection = xmlPage.channel.yweather::wind.@direction.toString();
row.Sunrise = xmlPage.channel.yweather::astronomy.@sunrise.toString();
row.Sunset = xmlPage.channel.yweather::astronomy.@sunset.toString();
row.City = xmlPage.channel.yweather::location.@city.toString();
}
var windDValue=parseInt(xmlPage.channel.yweather::wind.@direction.toString());
if(windDValue>0&&windDValue<45){
row.WindDirection="NNE";
}
else if(windDValue==0){
row.WindDirection="N";
}
else if(windDValue==45){
row.WindDirection="NE";
}
else if(windDValue>45&&windDValue<90){
row.WindDirection="ENE";
}
else if(windDValue==90){
row.WindDirection="E";
}
else if(windDValue>90&&windDValue<135){
row.WindDirection="ESE";
}
else if(windDValue==135){
row.WindDirection="SE";
}
else if(windDValue>135&&windDValue<180){
row.WindDirection="SSE";
}
else if(windDValue==180){
row.WindDirection="S";
}
else if(windDValue>180&&windDValue<225){
row.WindDirection="SSW";
}
else if(windDValue==225){
row.WindDirection="SW";
}
else if(windDValue>225&&windDValue<270){
row.WindDirection="WSW";
}
else if(windDValue==270){
row.WindDirection="W";
}
else if(windDValue>270&&windDValue<315){
row.WindDirection="WNW";
}
else if(windDValue==315){
row.WindDirection="NW";
}
else if(windDValue>315&&windDValue<360){
row.WindDirection="NNW";
}
else if(windDValue==360){
row.WindDirection="N";
}
var cityName=xmlPage.channel.yweather::location.@city;
//Modify the open weather url here if you are using your own API key
var params = {
url: "http://api.openweathermap.org/data/2.5/weather?q="+cityName+"&type=accurate&mode=xml&APPID=4abc8a3c9f101ccf9c7cfe7cbf3dfed7" /* STRING */,
timeout: 60 /* NUMBER */
};
var xmlPage = Resources["ContentLoaderFunctions"].LoadXML(params);
var isPrecipitation=xmlPage.precipitation.@mode;
if(isPrecipitation=="no"){
row.Precipitation="No Precipitations";
}
else
{
row.Precipitation=xmlPage.precipitation.@type+" "+xmlPage.precipitation.@value+" "+xmlPage.precipitation.@unit;
}
row.WindDirection=xmlPage.wind.direction.@name;
result.AddRow(row);
###############################################################
Thank you.
Hello,
This documentation is outdated. You can no longer use woeid with yahoo weather apps unless you are paying for an account with them (and even then I am not sure how much of that api is deprecated now). I recommend using Weather Underground (a.k.a. Wunderground).
You can find this documented on the PTC support sit here.
Hope this helps!
Tori