cloudy

Author Topic: NOAA RSS Advisory 2.0 PHP Script  (Read 39128 times)

0 Members and 1 Guest are viewing this topic.

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
NOAA RSS Advisory 2.0 PHP Script
« on: June 01, 2009, 03:17:40 AM »
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)
  • 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;
  • 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;
  • 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;

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


« Last Edit: September 25, 2009, 01:22:29 AM by MCHALLIS »

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,918
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #1 on: June 01, 2009, 04:33:19 AM »
Good work.   

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #2 on: June 01, 2009, 02:59:31 PM »
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 “urgency”, “severity”, and “certainty elements collectively distinguish less emphatic from more emphatic messages.
Code Values:
“Immediate” - Responsive action SHOULD be taken immediately
“Expected” - Responsive action SHOULD be taken soon (within next hour)
“Future” - Responsive action SHOULD be taken in the near future
“Past” - Responsive action is no longer required
“Unknown” - Urgency not known

Status:
Code Values:
“Actual” - Actionable by all targeted recipients
“Exercise”- Actionable only by designated exercise participants; exercise identifier should appear in <note>  
“System” - For messages that support alert network internal functions.
“Test” - Technical testing only, all recipients disregard
“Draft” – A preliminary template or draft, not actionable in its current form.

Message Type:
Code Values:
“Alert” - Initial information requiring attention by targeted recipients
“Update” - Updates and supercedes the earlier message(s) identified in <references>
“Cancel” - Cancels the earlier message(s) identified in <references>
“Ack” - Acknowledges receipt and acceptance of the message(s)) identified in <references>
“Error” indicates rejection of the message(s) identified in <references>; explanation SHOULD appear in <note>

Category:
Note:  Multiple instances MAY occur within a single <info> block.
Code Values:
“Geo” - Geophysical (inc. landslide)
“Met” - Meteorological (inc. flood)
“Safety” - General emergency and public safety
“Security” - Law enforcement, military, homeland and local/private security
“Rescue” - Rescue and recovery
“Fire” - Fire suppression and rescue
“Health” - Medical and public health
“Env” - Pollution and other environmental
“Transport” - Public and private transportation
“Infra” - Utility, telecommunication, other non-transport infrastructure
“CBRNE” – Chemical, Biological, Radiological, Nuclear or High-Yield Explosive threat or attack
“Other” - Other events

Source of information:
http://www.oasis-open.org/committees/download.php/15135/emergency-CAPv1.1-Corrected_DOM.pdf
« Last Edit: June 01, 2009, 03:21:50 PM by MCHALLIS »

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #3 on: June 01, 2009, 06:17:07 PM »
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 :)

An option to 'fetch-through' to the real alert text would be nice so folks don't get short-changed by the <summary> text display (fetch the link and save the <description> 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';
« Last Edit: June 01, 2009, 06:29:04 PM by MCHALLIS »

curly

  • Guest
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #4 on: June 01, 2009, 06:41:50 PM »
Nice work Mike!
 
 :signthanks:
 :salute:

Offline TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,918
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #5 on: June 01, 2009, 06:42:41 PM »

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.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #6 on: June 01, 2009, 06:51:51 PM »
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.
« Last Edit: June 01, 2009, 08:19:00 PM by MCHALLIS »

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #7 on: June 02, 2009, 12:13:58 AM »
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?
« Last Edit: June 02, 2009, 12:17:41 AM by MCHALLIS »

curly

  • Guest
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #8 on: June 02, 2009, 12:52:48 AM »
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.

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #9 on: June 02, 2009, 01:59:23 AM »
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.
« Last Edit: June 06, 2009, 09:35:34 PM by MCHALLIS »

Offline jahuff

  • Posts: 938
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #10 on: June 02, 2009, 11:15:37 AM »
Thanks Mike,

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

John

mth

  • Guest
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #11 on: June 02, 2009, 02:17:14 PM »
Mike,

Excellent work!  :)

I will install tonight to help with the feedback process.

Michael

Offline niko

  • syzygy
  • Global Moderator
  • Posts: 24,293
  • Crystal Ball broken! Please post the URL.
  • Northern California, U.S.A.
    • http://www.realweatherstation.com
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #12 on: June 02, 2009, 02:59:42 PM »
Wow, ace job there Mike  :D

Offline MCHALLIS

  • Posts: 2,150
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #13 on: June 02, 2009, 05:05:57 PM »
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.

mth

  • Guest
Re: NOAA RSS Advisory 2009 PHP Script (Beta)
« Reply #14 on: June 02, 2009, 08:52:33 PM »
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:
Code: [Select]
<?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:
Code: [Select]
<!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

 

cumulus