XML forecast script for Saratoga/Carterlake PHP/Ajax scripts

I wanted to pull the NWS forecast data from their XML feed and avoid the need to parse the NWS HTML files (which always concerned me as being too reliant on NWS web admins). I heavily modified the Carterlake/Saratoga-weather scripts and have something I’m getting pretty happy with. I figured I would share it so folks can use it if they want.

You can see the script in action at www.scottsh.net/wx2 - it feeds the dashboard as well as replaces the Forecast menu item.

If you want the script, you can get it (and the CSS file I used) at www.scottsh.net/wx2/xmlfcst.zip.

If you want to use it with the Carterlake/Saratoga-weather scripts like I have, you should replace the NWS forecast file with this one (for me, I changed advforecast2.php to xmlforecast.php). There are a couple of settings at the top of the file - the only critical one is the URL for the NWS XML forecast you want.

I have tried a range of lat/long settings from all over the US and so far I haven’t seen any unusual behavior except when picking a spot in Lake Michigan where I got a wave/water forecast.

Thanks! Very easy to setup.
http://www.harpersferry-weather.com/wxxmlfcst.php

Very Nice. One question.

Do you happen to know why the F symbol is below the Lo Temperature for each day on mine? Nothing is modified except for the location.

http://www.okawweather.com/wxforecastxml.php

Yes, very nice indeed!

http://saratoga-weather.org/xmlforecast.php (raw page)
http://saratoga-weather.org/nwsforecast.php (in site page)

Thanks!

I did a few tweaks to have it fit in my main site template :slight_smile:

Best regards,
Ken

@stooley - that’s interesting - it’s a problem only on IE6 (I don’t see it on FF3, IE8 or Chrome). The issue is that the width of the text is exceeding the 60px width I set for the TD element. If you open up xmlfcst.css find td.temps and change the width variable to 63px and it works correctly (at least on my IE6 test - let me know if it doesn’t for you.)

Anybody see a need to pull from the SOAP interface rather than HTTP? It wouldn’t be hard to modify this script to call that interface instead, but wondered if anybody else had an opinion?

NWS has a page on the SOAP interface here: http://www.nws.noaa.gov/forecasts/xml/

I might do it just to learn about how it works, but I was curious if anybody knew anything about the stability of either HTTP or SOAP interfaces that would make one or the other preferred?

Yea I am running IE8 here and had the issue. That change fixed it right up! Thanks!

@stooley - glad to hear it, I see now that it could happen with any browser assuming different text sizes. I should really take specific pixel widths out of the stylesheet and use percentages instead.

A few specific technical comments should somebody want to use it…

I don’t fill in every array entry that the advforecast2.php template does. I just filled in enough for the ajax-dashboard. I currently only create 2 entries for each of the forecasttext, forecasttitles, forecasticons, and forecasttemp arrays. If you need more entires, I put comments around what to modify.