lamiastella

GetOpenWeatherForecastData

Nov 8th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var stringLocation=location+" ";
  2. var arrayLocations=stringLocation.split(",");
  3. var lat=arrayLocations[0];
  4. var long=arrayLocations[1];
  5. var params = {
  6. url: "http://api.openweathermap.org/data/2.5/forecast?lat="+lat+"&lon="+long+
  7. "&units=imperial" +"&type=accurate&mode=xml" /* STRING */,
  8. timeout: 160 /* NUMBER */
  9. };
  10. // result: XML
  11. var xmlPage = Resources["ContentLoaderFunctions"].LoadXML(params);
  12. var params = {
  13. infoTableName : "InfoTable",
  14. dataShapeName : "OpenWeatherFeed"
  15. };
  16. // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(YahooWeatherFeed)
  17. var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
  18. var from_today_value=xmlPage.forecast.time[0].@from.substring(0,10);
  19. logger.warn("from_today_value= "+from_today_value);
  20. for each (var item in xmlPage.forecast.time) {
  21. var row = new Object();
  22. var from_current_value=item.@from.substring(0,10);
  23. if(from_current_value!=from_today_value){
  24. row.WindDirection = item.windDirection.@name;
  25. row.WindSpeed=item.windSpeed.@mps;
  26. row.WeatherTemp=parseFloat(item.temperature.@value);
  27. row.WeatherHumidity=parseFloat(item.humidity.@value);
  28. row.From=item.@from;
  29. row.To=item.@to;
  30. row.Title=xmlPage.location.name+" "+xmlPage.location.country;
  31. row.Precipitation=(item.precipitation.@type+" "+item.precipitation.@value)==" "?"No Precipitation":item.precipitation.@type;
  32. result.AddRow(row);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment