Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Weather XML SWA Help Request
This thread has 10 replies. Displaying all posts.
Post 1 made on Saturday May 29, 2010 at 14:31
pjjameso
Long Time Member
Joined:
Posts:
April 2008
73
I have captured and displayed sucessfully the text data from weather.com. Problem is when there isnt a swa (Severe Weather Alert) the xml tag in the data feed is not present and I get the following error in my prontoscript.

ProntoScript error: TypeError: weather.swa.a[0] has no properties

I assume an if statement could test whether there is data or not but am a bit stumped as to how to test. Any suggestions out there? Below is the snippet of code that is causing the problem.

// Display Severe Weather Alert
try {
var swa = weather.swa.a[0].t;
}
catch (e) {
var swa = "";
}

CF.widget("SWA").label = swa;
System.print("Severe Weather Alert: " +swa);

Thanks in advance...

Last edited by pjjameso on June 24, 2010 13:52.
Paul
Post 2 made on Sunday May 30, 2010 at 01:39
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
I think this might just work... What you want to do here is a check to see if the swa object exists using the known fact that javascript objects are sparsely populated arrays.

There are several ways to do this.
var swa = null;
if (weather['swa'])
{
swa = weather.swa.a[0].t;
}

OR

if (weather.hasOwnProperty('swa'))
{
swa = weather.swa.a[0].t;
}

The 2nd one, you can read about on google or the mozilla site as well as in Flanagan.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Tuesday June 1, 2010 at 12:45
n2hifi
Long Time Member
Joined:
Posts:
August 2007
192
O.K. how are you getting SWA's? My account used to get them and now that section is gone from the XML. I'm using:
xoap.weather.com/weather/local/USMO0204?cc=*&dayf=7&prod=xoap&unit=s&par=XXX&key=ABC
where XXX and ABC are my registered ID and key.
Mark Olsen, CTS
Cannon Design
OP | Post 4 made on Tuesday June 1, 2010 at 17:19
pjjameso
Long Time Member
Joined:
Posts:
April 2008
73
They are there only when there is a severe weather alert, otherwise they are not in the feed.
Paul
Post 5 made on Wednesday June 2, 2010 at 13:45
n2hifi
Long Time Member
Joined:
Posts:
August 2007
192
Yes, but last time we had tornado warnings in my area, they were on the website but not in the feed I was getting. I just checked the weather channel website for weather alerts and entered a city code for one that had severe weather warnings and I still don't get the section. It used to be if you took out the prod=xoap they would show up but they don't for me anymore.
Mark Olsen, CTS
Cannon Design
Post 6 made on Wednesday June 2, 2010 at 14:21
ScottGrimes
Long Time Member
Joined:
Posts:
April 2007
78
I'm not entirely sure why. Perhaps it is the difference between obtaining the data from the weather channel licenced host 'xoap' vs the 'xml' data. I'm pretty sure pjjameso is using the xml hack. I myself am using the xml data. I will try it out to see if it works.

licence site: socket.write("HOST:xoap.weather.com \r\n");
xml hack: socket.write("HOST:xml.weather.com \r\n");
Scott Grimes
Liquid Designs
[email protected]
OP | Post 7 made on Wednesday June 2, 2010 at 17:40
pjjameso
Long Time Member
Joined:
Posts:
April 2008
73
Scott,

You are correct, Im using the xml hack (thanks for pointing me in that direction!). Next time I have a swa I will check xoap and report back if swa is included in the data.
Paul
OP | Post 8 made on Thursday June 24, 2010 at 13:43
pjjameso
Long Time Member
Joined:
Posts:
April 2008
73
Next question regarding multiple swa alerts, hoping its a quick modification! In the code below I am receiving multiple swa's from weather.com. Im am displaying the first alert of the three recieved below correctly. How would one loop to pick up the remaining alerts since they all seem to have the same xml tag?


 //<swa>
- <a id="628896" uc="1">
  <t>Special Weather Statementt>
  <l>[Link: weather.com]l>
  a>
- <a id="618609" uc="0">
  <t>Air Quality Alertt>
  <l>[Link: weather.com]l>
  a>
- <a id="636930" uc="1">
  <t>Severe Thunderstorm Watch until Thu Jun 24 2010 08:00 PM EDTt>
  <l>[Link: weather.com]l>
  a>
  swa>\\

// Display Severe Weather Alert
try {
var swa = weather.swa.a[0].t;
}
catch (e) {
var swa = "";
}

CF.widget("SWA").label = swa;
//System.print("Severe Weather Alert: " +swa);

Thanks as always!

Last edited by pjjameso on June 24, 2010 13:52.
Paul
Post 9 made on Thursday June 24, 2010 at 15:05
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
var swa0 = weather.swa.a[0].t;
var swa1 = weather.swa.a[1].t;
var swa2 = weather.swa.a[2].t;

OR

var i;
var swa_t = [];
if (weather && weather.swa && weather.swa.a)
{
for (i=0; i < weather.swa.a.length; i++)
swa_t[i] = weather.swa.a[i].t;
}

ECMA 357 PDF (E4X) should provide some relevant examples as well.
Other stuff regarding for loop can be found in Flanagan.

:-)
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 10 made on Thursday June 24, 2010 at 15:42
pjjameso
Long Time Member
Joined:
Posts:
April 2008
73
Lyndel,

Thanks again and again! Picked option one, quick and easy modification. Also thanks for the ECMA reference material. Learning a bit day by day.
Paul
Post 11 made on Thursday June 24, 2010 at 19:47
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
See the "Further Reading" section of the "Dev Guide" for more helpful stuff.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse