Author Topic: Anybody written a script to read this NWS output?  (Read 1307 times)

0 Members and 1 Guest are viewing this topic.

Offline JPB

  • Member
  • *
  • Posts: 20
Anybody written a script to read this NWS output?
« on: November 24, 2012, 11:16:13 AM »
It's XML output from the NWS. Here is a URL with an example near my home:

http://www.wrh.noaa.gov/forecast/xml/xml.php?duration=168&interval=6&lat=37.2&lon=-122.0

This page seems to have some interesting properties:

  • It is in a standard XML format. So it won't be subject to the kind of changes seen when scripts scrape info from web-pages.
  • It contains enough information that a standard set of icons and some table formatting, when combined with this output, could allow us to make a pretty detailed '5 or 7 day forecast' page.

If there is no script available to parse this, I am tempted to write one, over the next while (time is not always available to me), that would be in multiple parts:

1) Read the forecast every few hours (for those websites with cron capability), or at explicit stimulation by a function call via a web-page include. (You could have something on a windows box that goes to a url of your choice periodically). The forecast would be read and put not into a table but would generate a PHP script that contained the XML output, with the following additions, in a series of arrays:
  day of week in local time zone, as best as PHP can determine it from UTC
  day of month in local time zone, as best as PHP can determine it from UTC
  month of year in local time zone, as best as PHP can determine it from UTC
  year in local time zone, as best as PHP can determine it from UTC
  hour in local time zone, as best as PHP can determine it from UTC
  minute in local time zone, as best as PHP can determine it from UTC
  suggested icon to use from the Carter Lake set that everyone seems to use. (this will be the trickiest part and most subjective. At what point is 'rain likely' vs. 'rain possible' vs. 'slight chance of rain'
  textual description of the forecast for this line. (this also will be tricky as it's subjective in some ways)

2) A script, that on being included, generates the typical 'row of graphics + text underneath' that weather websites have

3) A script, that on being included, generates a textual form of the above, as a series of lines.

Maybe #2 and #3 should be parts of #1, with the 'forecast graphics+small text row' and the 'text forecast list' generated one time, and those final results calculated... with a new pair of scripts that utilizes that information... dunno...

But before I even consider beginning this, I am curious as to if this already exists, and if it doesn't, if anyone else would find this useful. This will also be me teaching myself PHP (I know other languages quite well, this part looks fairly straightforward).

Davis Pro 2, Meteohub

Offline capeweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 1259
    • http://www.capeweather.com

Chris
Cape Coral, Florida
Website: http://www.capeweather.com
Website: http://www.fortmyersweather.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6226
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Anybody written a script to read this NWS output?
« Reply #2 on: November 24, 2012, 12:41:03 PM »
The URL you showed for the XML

http://www.wrh.noaa.gov/forecast/xml/xml.php?duration=168&interval=6&lat=37.2&lon=-122.0

is likely better suited to doing a 'meteogram' than a text/icon based forecast such as provided by the advforecast2.php script.

I'd been playing with the XML forecast using URLs like:

http://forecast.weather.gov/MapClick.php?lat=37.27153397&lon=-122.02274323&FcstType=dwml

But... the issue is that when the point-printable forecast is not available, it does a redirect to the Zone HTML forecast (which screws up an XML parser) -- it's because they don't have a good 'failover' for their XML feed that I'd not done more with it.  Right now, only the point-printable HTML forecast does a failover to the HTML Zone forecast when the digital forecast for the location is not available.

You are correct, that using simple_xml to parse the results is a fairly straighforward task .. just make sure that the NWS URL does return XML and not a 302-redirect (or even stranger, a JavaScript snippet that resets window.location to the Zone HTML).  Drives me a bit nuts sometimes...

Best regards,
Ken

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline JPB

  • Member
  • *
  • Posts: 20
Re: Anybody written a script to read this NWS output?
« Reply #3 on: November 26, 2012, 04:17:07 PM »
UPDATE:

I have learned more than I thought I would need to know concerning various formats of raw weather data from the USA National Weather Service!

Right now, I seem to be getting an interesting XML result from the NWS. I like it because it even suggests icons for use, and from the weather descriptions you could even create text instead of relying on text given by the NWS.

Please don't click it constantly as I do not have caching enabled for this - it's pulling from NWS each time. The XML package I am using allows for caching easily enough; I just need to go through the work of using this.





« Last Edit: December 02, 2014, 01:30:46 PM by JPB »
Davis Pro 2, Meteohub

Offline mpotts95420

  • Member
  • *
  • Posts: 6
    • websites designed by the Caspar Institute
Re: Anybody written a script to read this NWS output?
« Reply #4 on: August 13, 2017, 04:24:25 PM »
Sorry to get here so late. I didn't know about WXForum until I tried to solve the recent (August 1st?) failure of a very successful parsing script I wrote. I'm going to follow the forum's advice and start a new topic, "forecast/xml/xml.php" but here's what I *used* to have working beautifully on my family website:
 [ You are not allowed to view attachments ]

 

anything