NOAA RSS Advisory 2.0 PHP Script

I have modified Ken True’s NOAA RSS Advisory PHP script to a new version 2.0 that is specific to the new beta NWS Atom feeds.

The script is back to being maintained by Ken True
NOAA ATOM/CAP Advisory PHP script
http://saratoga-weather.org/scripts-atom.php#atomadvisory

No longer BETA

Renamed to atom-advisory.php to avoid confusion and allow coexistence with
rss-advisory.php which used the RSS feeds instead of the ATOM/CAP feeds.

What’s New:

  • Modified to use the Experimental XML/CAP 1.1 Feeds (these alerts are available now and are going to be the standard rss alerts beginning in Dec. 2009. The old alerts are to be phased put.)
  • Displays new information called “CAP codes”. The CAP codes provide: Last updated time, Effective time, Expires time, Urgency, Severity, Certainty, Status, Message type, Alert Category, and Areas affected. When there is an Urgency: “Immediate” alert, the word “Immediate” will be in red highlights to stand out better.
  • Added a link “…view the complete message” on each alert so you can read the complete message on the NWS web site.
  • When there is an alert, it automatically displays a header title at the top of the advisories page that includes the zone name and zone code. ie: “Current Watches, Warnings and Advisories for Midland (TXZ062) Texas Issued by the National Weather Service”. This new feature compliments the feature that lets you change the zone code by adding a query on the URL ie: rss-advisory.php?zone=TXZ062
  • When there is an active alert, it automatically displays a “source” url link at the bottom of the advisories page that links directly to the rss page where the script got the alerts. ie: “Source: NWS Watches, Warnings or Advisories for zone TXZ062”. This new feature compliments the feature that lets you change the zone code by adding a query on the URL ie: rss-advisory.php?zone=TXZ062
  • New setting: $fullMessagesMode = true; // fetches the complete message for each alert.
  • New setting: $doLongTitles = true; // adds the zone name to the Alert Title for each alert.
  • Better usage of $doLowerCase setting. It will now lowercase all, then attempt to uppercase first word of every sentence.
  • Cache file improvements - cache files are now only written to the server when there is a valid zone selected
  • Fixes for handling invalid zones - now checks both input and default zone configuration for both syntax and actual existence of the NOAA zone. If a bogus zone is offered, it does not write any cache files and then displays “Advisory Information Unavailable, invalid advisory zone selected.”
  • Better error handling for when the NOAA servers are having problems. View the HTML source for debugging comments.
  • Misc. fixes and improvements

Known Issues: (all fixed)

  • [li]NWS provides this new feed with a shortened “summary”, this can cause the displayed message to be shorter than the complete message that is available, click the link “view the complete message” on the alert to read the complete message on the NWS web site. (This issue has been reported to NWS, but their intent is for you to click to read the complete message for more information and instructions. So this is actually working the way they designed it.)
    Fixed to workaround this problem, set $fullMessagesMode = true; [/li]
  • The alert message may be missing the “instructions” section. Because the NWS only provides this new feed with a shortened “summary”, you have to click the link “view the complete message” on the alert to read the complete message on the NWS web site. (This is the way the NWS designed the new alerts. This is to save resources by not showing the full details for some of the messages you may not be interested in viewing in detail.) Fixed to workaround this problem, set $fullMessagesMode = true;

    [li]The short summary message text sometimes has run-together words (This issue has been reported to NWS, hopefully they will fix it before the beta stage ends in December 2009.)
    Fixed to workaround this problem, set $fullMessagesMode = true;[/li]

Note:
This version requires PHP5 and is not backwards compatible with the non-beta feeds.
Your NOAA RSS Advisory PHP script will require an upgrade to this version by December of 2009 (you can start using it now if you want).

Try a demo of it on my web site:
Stand alone page:
http://www.642weather.com/weather/rss-advisory.php?zone=AKZ224 (change the zone as needed to test)

Included style page:
http://www.642weather.com/weather/advisories.php?zone=AKZ224 (change the zone as needed to test)

Look here to find zones that have active warnings (hint: Alaska might some active ones now, or look on a national map for an area with warnings.)
http://www.weather.gov/alerts-beta/

Download:
http://saratoga-weather.org/atom-advisory.php?sce=view

Good work.

A list of possible alert messages:
http://www.nws.noaa.gov/alerts/product_list.txt

Here is some information on CAP code values and their meanings:

Urgency, Severity, and Certainty:
The

I added a few features suggested by Ken True:

He said:
"I’d suggest that a detection for PHP5 be inserted in the script, since you’re using simple_xml function and that could save a few trouble calls :slight_smile:

An option to ‘fetch-through’ to the real alert text would be nice so folks don’t get short-changed by the

text display (fetch the link and save the for display if the non-summary mode is active)."

I added detection for installations less than PHP5 and a failure message.

I just added a new feature/setting to workaround the short message problem:
You just download the latest version from the first post, then set $fullMessagesMode = true;
It will fetch (in realtime) the complete message and instructions(if available) for all the messages when alerts are viewed in non-summary mode.

I also added a fine versioning number after the word BETA so you can tell if I have made slight edits or not.
$Version = ‘V2.00 01-Jun-2009 BETA .002’;

Nice work Mike!

:signthanks:
:salute:

Since you are using PHP5, how about a Curl replacement for direct URL file gets?

This would allow a site that has URL file restrictions to still use the script using a Curl alternative.

Then you could use simplexml_load_string instead of simplexml_load_file to parse the same data using a simple switch in the script.

I’ve run into problems a number of times recently where the ISP blocked file URL access but Curl worked fine.

BTW I don’t write for PHP4 any longer.

Ok thanks for the suggestions. Some installations do not have CURL, but most do. I can do a CURL check, then fall back to other way if they do not have CURL.

If anybody still has PHP4 they probably have a compromised server. They need to ask web host to upgrade their account to a server with PHP5.

New Curl version is working on my test server, but I need to adjust a few minor things and have to go out for an hour. I will upload it later.

Just uploaded the new version with CURL support. It took awhile to test all the debugging info you see if you view the source.
V2.00 01-Jun-2009 BETA .004

Any testers?

V2.00 01-Jun-2009 BETA .004 The CURL feature checks out OK with multiple alerts, one alert, no alerts and a bad zone entered.

V2.00 01-Jun-2009 BETA .005 - added proper fail message for when an invalid advisory zone is selected.

update - protect zone value input. allowed zone = [2letters][Z][3numbers]
this is critical because the zone input determines part of the cache file names that are written on the server.

Thanks Mike,

V2.00 01-Jun-2009 BETA .005 installed and seems to be working fine.

John

Mike,

Excellent work! :slight_smile:

I will install tonight to help with the feedback process.

Michael

Wow, ace job there Mike :smiley:

V2.00 02-Jun-2009 BETA .006

file cache improvement - cache files are never written to the server unless there is a valid zone selected or set in settings. Before it would make an empty cache file anyway.

Hi Mike,

Added to a temporary area of my site: http://www.relayweather.com/wxadvisory-2009.php

One thing I noticed is that I loose my background color. Upon investigation, it seems like the script pulls some extra data.

Here is my call:

<?php include("http://www.relayweather.com/rss-advisory-2009.php"); ?>

Take a look at the source of my code. When the script is called it pulls the following “extra” information:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RSS Advisory Script</title>
</head>
 
<body style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
<!-- rss-advisory-2009.php - V2.00 02-Jun-2009 BETA .006 -->
<!-- getting new file from http://www.weather.gov/alerts-beta/wwaatmget.php?x=MDZ011 -->
<!-- CURL GET /alerts-beta/wwaatmget.php?x=MDZ011 HTTP/1.0 Host: www.weather.gov -->
<!-- Time to fetch: 0.697 sec -->
<!-- cache saved to rss-advisory-2009-MDZ011.txt -->

Is this normal for the script?

Michael

Michael,
Instead of this on your page

 <?php include("http://www.relayweather.com/rss-advisory-2009.php"); ?>

Try this


<?php
 $_REQUEST['zone'] = 'MDZ011';
 $_REQUEST['inc'] = 'Y';
 $_REQUEST['noprint'] = 1;
 include 'rss-advisory-2009.php';
 if (preg_match("|There are no active|i",$advisory_html) ||
     preg_match("|Advisory Information Unavailable|i",$advisory_html)) {
       echo '<div class="advisoryBoxnoactive">' .$advisory_html .'</div>';
 }else{
       echo $advisory_html;
 }
?>

This corrected the problem. Thanks Curly!

V2.00 02-Jun-2009 BETA .007

added a code fix suggested by curly: Sometimes the word " issued" isn’t included in the entry title so it won’t explode properly to “Tornado Watch”.

added more fixes for handling invalid zones - now checks both input and default zone configuration for both syntax and actual existence of the NOAA zone. If a bogus zone is offered, it does not write any cache files and then displays “Advisory Information Unavailable, invalid advisory zone selected.”

Various code cleanup.

I’m using $_REQUEST[‘summary’] = ‘Y’; on a test page (http://www.harpersferry-weather.com/wxadvisory-2009.php). There are no watches, warnings, and advisories. What is returned is a link “Source: NWS Watches, Warnings or Advisories for zone WVZ053” only. I was expecting it should return something like "There are no active watches, warnings or advisories for zone WVZ053. "

<?php $_REQUEST['zone'] = 'WVZ053'; $_REQUEST['inc'] = 'Y'; $_REQUEST['summary'] = 'Y'; $_REQUEST['noprint'] = 1; include 'rrs-advisory-2009.php'; if (preg_match("|There are no active|i",$advisory_html) || preg_match("|Advisory Information Unavailable|i",$advisory_html)) { echo '
' .$advisory_html .'
'; }else{ echo '
' . $advisory_html .'
'; } ?>

John

Thanks for testing. :smiley:
I may have broke something in my last update. 8O
I will test it some more and let you know.

Edit: found the problem… new beta soon.