cloudy

Author Topic: NOAA RSS Top Warning 2.0 PHP Script  (Read 13108 times)

0 Members and 1 Guest are viewing this topic.

Offline Zalmor

  • Posts: 550
  • Erin, NY
    • Zalmors' corner of the Web
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #75 on: September 22, 2009, 02:45:45 PM »
NOAA RSS Top Warning 2.0 PHP Script

Version 2.01 - 01-Sep-2009   Fixed blank output when Air Quality Alert, improved top alert selection
If it cannot figure out which alert is the top most alert, it will select the 1st one.

Small but minor bug I think.

When Advisory Information Unavailable, error fetching or reading data shows up, my page footer.php is off  :roll:
Normally my footer shows the whole width at the bottom of the screen.  Just noticed this recently.  It only appears when the above shows up.

Does this when I use http://www.642weather.com/weather/top-warning.php?zone=NYZ024 from your demo test site link also.
« Last Edit: September 22, 2009, 02:51:28 PM by Zalmor »
Michael A

Windows XP Pro SP3, Pentium D 2.80GHz 3GB RAM, Quickcam Pro 4000, and APC

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #76 on: September 22, 2009, 02:50:03 PM »
It's because the feed seems to be returning only 'n/a' as the contents, not the full XML.  It's doing it for my zone too.
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline Zalmor

  • Posts: 550
  • Erin, NY
    • Zalmors' corner of the Web
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #77 on: September 22, 2009, 02:56:01 PM »
It's because the feed seems to be returning only 'n/a' as the contents, not the full XML.  It's doing it for my zone too.

OK, maybe Mike can put in a catch for when this happens in the next build.   :roll:
Michael A

Windows XP Pro SP3, Pentium D 2.80GHz 3GB RAM, Quickcam Pro 4000, and APC

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #78 on: September 22, 2009, 03:07:05 PM »
Looks like it needs a change in the script from
Code: [Select]
    fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");  to
Code: [Select]
    fputs($socketConnection, "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");
Seems it no longer likes HTTP 1.0 and needs HTTP 1.1 requests .. then it works again :)

I've updated the atom-advisory.php and atom-top-warning.php scripts on my site with this change.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline Zalmor

  • Posts: 550
  • Erin, NY
    • Zalmors' corner of the Web
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #79 on: September 22, 2009, 03:33:10 PM »
Looks like it needs a change in the script from
Code: [Select]
    fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");  to
Code: [Select]
    fputs($socketConnection, "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");
Seems it no longer likes HTTP 1.0 and needs HTTP 1.1 requests .. then it works again :)
I've updated the atom-advisory.php and atom-top-warning.php scripts on my site with this change.

Ken

Will give that a try, Thanks.
Michael A

Windows XP Pro SP3, Pentium D 2.80GHz 3GB RAM, Quickcam Pro 4000, and APC

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #80 on: October 28, 2009, 04:30:49 PM »
NWS recently added County codes in addition to Zone codes.

Below is the change to allow Zone or County codes.

change:
Code: [Select]
//  set desired zone
$Zone = $DefaultZone;
$invalid_zone = 0;
if (!preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $Zone)) {
  $invalid_zone = 1; // valid zone syntax from $DefaultZone setting
}
// mchallis added security update - protect zone value input. allowed zone = [2letters][Z][3numbers]
if (isset($_GET['zone']) && preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $_GET['zone'])) {
  $Zone = $_GET['zone'];  // valid zone syntax from input
} else if (isset ($_GET['zone']) && !preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $_GET['zone'])) {
  $invalid_zone = 1;   // invalid zone syntax from input
}


to:
Code: [Select]
//  set desired zone
$Zone = $DefaultZone;
$invalid_zone = 0;
if (!preg_match("/^[a-z]{2}[C|Z][0-9]{3}$/i", $Zone)) {
  $invalid_zone = 1; // valid zone syntax from $DefaultZone setting
}
// mchallis added security update - protect zone value input. allowed zone = [2letters][C or Z][3numbers]
if (isset($_GET['zone']) && preg_match("/^[a-z]{2}[C|Z][0-9]{3}$/i", $_GET['zone'])) {
  $Zone = $_GET['zone'];  // valid zone syntax from input
} else if (isset ($_GET['zone']) && !preg_match("/^[a-z]{2}[C|Z][0-9]{3}$/i", $_GET['zone'])) {
  $invalid_zone = 1;   // invalid zone syntax from input
}
« Last Edit: October 28, 2009, 11:56:06 PM by MCHALLIS »

Blackjack52

  • Guest
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #81 on: October 28, 2009, 05:04:23 PM »
Thank you.

Offline K3JAE

  • Posts: 696
  • Fayette County, PA., USA
    • K3JAE's Weather Station
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #82 on: October 28, 2009, 10:51:00 PM »
NWS recently added County codes in addition to Zone codes.

Below is the change to allow Zone or County codes.

change:
Code: [Select]
//  set desired zone
$Zone = $DefaultZone;
$invalid_zone = 0;
if (!preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $Zone)) {
  $invalid_zone = 1; // valid zone syntax from $DefaultZone setting
}
// mchallis added security update - protect zone value input. allowed zone = [2letters][Z][3numbers]
if (isset($_GET['zone']) && preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $_GET['zone'])) {
  $Zone = $_GET['zone'];  // valid zone syntax from input
} else if (isset ($_GET['zone']) && !preg_match("/^[a-z]{2}Z[0-9]{3}$/i", $_GET['zone'])) {
  $invalid_zone = 1;   // invalid zone syntax from input
}


to:
Code: [Select]
//  set desired zone
$Zone = $DefaultZone;
$invalid_zone = 0;
if (!preg_match("/^[a-z]{2}C|Z[0-9]{3}$/i", $Zone)) {
  $invalid_zone = 1; // valid zone syntax from $DefaultZone setting
}
// mchallis added security update - protect zone value input. allowed zone = [2letters][C or Z][3numbers]
if (isset($_GET['zone']) && preg_match("/^[a-z]{2}C|Z[0-9]{3}$/i", $_GET['zone'])) {
  $Zone = $_GET['zone'];  // valid zone syntax from input
} else if (isset ($_GET['zone']) && !preg_match("/^[a-z]{2}C|Z[0-9]{3}$/i", $_GET['zone'])) {
  $invalid_zone = 1;   // invalid zone syntax from input
}

Mike;

Dumb question maybe but... Do we need to input our County codes someplace or will it use the files already coded? Currently I only have $myDefaultZone = 'PAZ032'; in that file.
« Last Edit: October 28, 2009, 10:54:10 PM by K3JAE »


73's de K3JAE

John
K3JAE Weather Station

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #83 on: October 28, 2009, 11:54:27 PM »
Depends on if you want to monitor zone or county.  This script cannot monitor both.
NWS just added this County feature. It seems redundant to the Zones.
I cannot find any announcement about it anywhere.

So how are we supposed to use it?
Are they discontinuing zones in favor of counties?
Can somebody contact NWS and find out?

Offline MCHALLIS

  • Posts: 2,102
  • Long Beach, WA USA
    • Weather for Long Beach, WA USA
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #84 on: October 28, 2009, 11:56:40 PM »
slight change in the code I posted. [C|Z]

Offline K3JAE

  • Posts: 696
  • Fayette County, PA., USA
    • K3JAE's Weather Station
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #85 on: October 29, 2009, 03:28:08 AM »
Depends on if you want to monitor zone or county.  This script cannot monitor both.
NWS just added this County feature. It seems redundant to the Zones.
I cannot find any announcement about it anywhere.

So how are we supposed to use it?
Are they discontinuing zones in favor of counties?
Can somebody contact NWS and find out?

I can say without absolute certainty that when a flood statement in my specific area or a Special Weather Statement is issued our NWS office uses County codes and there may be another couple of alerts issued that way but the bulk of "summertime" alerts are issued via Zone. As for wintry weather, that remains to be seen.

I seem to recall reading somewhere that the NWS is looking to be more specific in their alerts so may resort to locales within counties/zones...


73's de K3JAE

John
K3JAE Weather Station

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #86 on: October 30, 2009, 06:13:21 PM »
The WD/AJAX/PHP USA distribution was updated with the changed script.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline Harry

  • Posts: 444
  • Union City, CA USA
    • Union City, CA Weather
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #87 on: October 30, 2009, 07:21:54 PM »
I can say without absolute certainty that when a flood statement in my specific area or a Special Weather Statement is issued our NWS office uses County codes and there may be another couple of alerts issued that way but the bulk of "summertime" alerts are issued via Zone. As for wintry weather, that remains to be seen.

I seem to recall reading somewhere that the NWS is looking to be more specific in their alerts so may resort to locales within counties/zones...

I have seen that too in my area.  99% of the time, they will use the zone and for flood statements, they use the county code which shows up in the feed with a question mark i.e. CAC001(?).  Using the county code would make more sense if the event was only for a specific county because the zone I am in (CAZ508), covers several counties.
« Last Edit: October 30, 2009, 07:23:44 PM by Harry »

Offline K3JAE

  • Posts: 696
  • Fayette County, PA., USA
    • K3JAE's Weather Station
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #88 on: October 31, 2009, 03:49:21 AM »
Discovering a new problem;

When I have an error fetching the info... I get the following issue...

The page format is screwed up.. and it appears an extra <DIV> tag is lurking someplace or a </DIV> tag is missing (which I am pretty positive is where the issue lies) as it screws up the footer as well. This AFTER the "[C|Z]" fix was incorporated.

  • The Ajax-dashboard area over runs it's borders.
  • The top warning area actually goes entire length of page and stops at footer as evidenced by the greenish background about 2/3's down the attached image and can be seen running through the ajax data area.
  • The Footer is contained within the Main-copy <DIV> tag.

So long as the fetch is successful there is no error and page formats and displays correctly. When the fetch error happens (which seems to be happening rather frequently lately) this page displays incorrectly. Can someone advise where the missing </DIV> tag should be located?
« Last Edit: October 31, 2009, 03:59:12 PM by K3JAE »


73's de K3JAE

John
K3JAE Weather Station

Offline K3JAE

  • Posts: 696
  • Fayette County, PA., USA
    • K3JAE's Weather Station
Re: NOAA RSS Top Warning 2.0 PHP Script
« Reply #89 on: October 31, 2009, 04:01:45 AM »
Believe I successfully found the above listed problem and it appears the same problem of Zalmore's listed at top of this thread page. lf I cannot say for sure if it is a package error or if it was an error on my part (although I do not recall modifying this area at all).  

So in other words suggest checking the script to see if it is a syntax error in the package.

I found this:
Code: [Select]
 $returnstring = "<div class=\"advisoryBoxnoactive\">Top Warning Information Unavailable, error fetching or reading data from the
<a href=\"$RSS_URL\">NOAA advisories server.</a><div>\n";


and replaced it with this:
Code: [Select]
 $returnstring = "<div class=\"advisoryBoxnoactive\">Top Warning Information Unavailable, error fetching or reading data from the
<a href=\"$RSS_URL\">NOAA advisories server.</a></div>\n";


Notice the <DIV> tag at the end was NOT properly closed but instead a new <DIV> was opened.
« Last Edit: October 31, 2009, 04:01:21 PM by K3JAE »


73's de K3JAE

John
K3JAE Weather Station

 

cumulus