Author Topic: Active Weather Alert display  (Read 7078 times)

0 Members and 1 Guest are viewing this topic.

Offline neondesert

  • Forecaster
  • *****
  • Posts: 628
    • http://www.neondesertweather.com
Active Weather Alert display
« on: October 06, 2007, 08:30:21 PM »
Quote from: "Chris from capeweather"

Yes, very cool. I sure would like to know how he got his 'Active weather alert' to automatically display with a link. Didn't mean to get off track but thought that would be a cool addition. If anybody knows could they post in the script forum?  :)


Thanks for the compliment Chris!  :D

Here is how I implemented this feature.

First, create a php file with the following code:
Code: [Select]
<?php
// Check the current advisory text file size and display an alert gif and text if an advisory is issued
$size filesize&#40;"rss-advisory-NVZ020.txt"&#41;;
if&#40;$size > 1160&#41; //1160 is the "approx" min size of rss-advisory-ZONE.txt
&#40;$warn = "<img src='anim-led-red.gif'>"&#41; && &#40;$warntext = " Active Weather Alert Click For Details "&#41;;
?>


As you can see, I am using Ken's advisory script(Thanks Ken! :wink: ) , but you may use a different  source file for warnings/advisories.

Next, use this include on the pages you want to have an alert link:
Code: [Select]
<?php include "alertGif.php"?> // use the name of your php file

Finally, place this code at the location on the page you would like the display to appear:
Code: [Select]
<?=$warn;?><a href="Path to your advisory page" target="_self"><?=$warntext;?></a><?=$warn;?>

There are probably more elegant ways to do this, but hey it works!


I'd like to thank Matt at http://www.weatherbus.com for his help, as he uses a similar display on his site.  :)
Larry
"But it's a DRY Heat!"


Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Active Weather Alert display
« Reply #1 on: October 06, 2007, 09:41:41 PM »
Thanks for the script, Larry!

Okay, I'm green: how do I obtain the file:

   rss-advisory-NVZ020.txt

on my server? I know my zone number; I just don't know how I obtain that file.

Thanks!

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6654
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Active Weather Alert display
« Reply #2 on: October 06, 2007, 10:56:05 PM »
Kevin,
I think Larry is using the rss-advisory-test-c.php (Caching RSS advisory script) from http://saratoga-weather.org/scripts-rss.php#NOAARSS

The rss-advisory-ZONE.txt file is the cache file from the script.

Larry, you and Matt are very clever in the use of the 'appearing warning'..  I'll have to look at that for my site too.  Thanks!

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 WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Active Weather Alert display
« Reply #3 on: October 06, 2007, 11:01:48 PM »
Quote from: "saratogaWX"
Kevin,
I think Larry is using the rss-advisory-test-c.php (Caching RSS advisory script) from http://saratoga-weather.org/scripts-rss.php#NOAARSS

The rss-advisory-ZONE.txt file is the cache file from the script.

Best regards,
Ken

Great! I'll take a look at that.

As always --- thanks, Ken!

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline WeatherHost

  • Forecaster
  • *****
  • Posts: 3095
Re: Active Weather Alert display
« Reply #4 on: October 07, 2007, 07:01:35 AM »
I've looked at a few of these other scripts, but I still like the one from CarterLake.  It hasn't failed me yet.
Banners, tags, widgets, etc. are why I have Signatures turned off.

Offline capeweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 1265
    • http://www.capeweather.com
Re: Active Weather Alert display
« Reply #5 on: October 07, 2007, 01:07:26 PM »
Quote from: "neondesert"
Quote from: "Chris from capeweather"

Yes, very cool. I sure would like to know how he got his 'Active weather alert' to automatically display with a link. Didn't mean to get off track but thought that would be a cool addition. If anybody knows could they post in the script forum?  :)


Thanks for the compliment Chris!  :D

Here is how I implemented this feature.

First, create a php file with the following code:
Code: [Select]
<?php
// Check the current advisory text file size and display an alert gif and text if an advisory is issued
$size filesize&#40;"rss-advisory-NVZ020.txt"&#41;;
if&#40;$size > 1160&#41; //1160 is the "approx" min size of rss-advisory-ZONE.txt
&#40;$warn = "<img src='anim-led-red.gif'>"&#41; && &#40;$warntext = " Active Weather Alert Click For Details "&#41;;
?>


As you can see, I am using Ken's advisory script(Thanks Ken! :wink: ) , but you may use a different  source file for warnings/advisories.

Next, use this include on the pages you want to have an alert link:
Code: [Select]
<?php include "alertGif.php"?> // use the name of your php file

Finally, place this code at the location on the page you would like the display to appear:
Code: [Select]
<?=$warn;?><a href="Path to your advisory page" target="_self"><?=$warntext;?></a><?=$warn;?>

There are probably more elegant ways to do this, but hey it works!


I'd like to thank Matt at http://www.weatherbus.com for his help, as he uses a similar display on his site.  :)


Larry,
You're welcome! Thanks so much for posting this information and I really appreciate it. I've started working on it a little bit and hope to have it complete soon. I just need to figure out how to get the link to automatically scroll down to my RSS-Advisory feed on my main page courtesy of Ken.

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

Offline WeatherBeacon

  • Chief
  • Forecaster
  • *****
  • Posts: 1369
    • http://www.wxbeacon.com
Re: Active Weather Alert display
« Reply #6 on: October 07, 2007, 03:58:21 PM »
Quote from: "WeatherHost"
I've looked at a few of these other scripts, but I still like the one from CarterLake.  It hasn't failed me yet.

Yes, I use that script, too, but I believe the question here is how Larry (neondesert) created a clickable alert link that appears when there's an advisory or warning.

Regards,

Kevin...
Mae govannen!
Kevin  (Member AMS) http://www.wxbeacon.com               Genesee County, Michigan
Hardware:  Davis Vantage Pro Wireless, Midland WR-300
Software: VWS 14.01p43, WeatherFlash, & GRLevel3

Offline capeweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 1265
    • http://www.capeweather.com
Re: Active Weather Alert display
« Reply #7 on: October 09, 2007, 12:45:22 AM »
Well I finally got mine up and running! Thanks for the help Ken with the scroll down link. No active warnings at this time but it will appear above my wind readings in the center with a clickable link to the rss-advisory on the homepage. Ken provided some cool html coding to allow my page to scroll down. I'll post it in here. Hope that was ok Ken.

Quote
For the scroll-down-link in the same page, it's in two parts.

The 'clickable link' looks like:
Code: [Select]
<a href="#scrolltosomename">Text that's hotlinked</a>

Later in the page you put:
Code: [Select]
<a name="scrolltosomename" id="scrolltosomename"></a> just above where you want to browser to park the top of the page.

Then when they click on the link, it will scroll to the <a name="..."> that matches.


Thanks again Larry for sharing this cool script!

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

Offline WeatherHost

  • Forecaster
  • *****
  • Posts: 3095
Re: Active Weather Alert display
« Reply #8 on: October 09, 2007, 03:10:34 AM »
Quote from: "WeatherBeacon"
Quote from: "WeatherHost"
I've looked at a few of these other scripts, but I still like the one from CarterLake.  It hasn't failed me yet.

Yes, I use that script, too, but I believe the question here is how Larry (neondesert) created a clickable alert link that appears when there's an advisory or warning.

Regards,

Kevin...


That's how I have mine working.  The Alert Text is displayed on one page, but I have clickable links on two other pages when alerts are active.  I'm doing it with a Virtual statement;
Code: [Select]
<!--#include virtual="/advisorynew.php" -->
where "advisorynew.php" is the name of the page with the script and full text.

The script itself is edited to add a " The National Weather Service has issued a (alert type) for (local area). Click here for full message text. ", as a clickable link so that it's more public user friendly and descriptive.
Banners, tags, widgets, etc. are why I have Signatures turned off.

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: Active Weather Alert display
« Reply #9 on: October 09, 2007, 08:06:15 AM »
Uh guys... not to interrupt... but... this stuff is pretty simple.

It's the difference between being able to copy/paste code and write a little of your own.

With either Javascript or PHP, it's as simple as an if statement.

if (there is an advisory) then display some HTML code...

else... display some other HTML code or nothing.

After doing that, you might consider changing the advisory that is displayed based on the severity.... so an advisory is say yellow, a watch is orange, and a warning is red. Or make one scroll and the other static... or add a graphic... or or or... it's really up to your imagination.

If I get a minute tonight, I'll post exactly the code I use.

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: Active Weather Alert display
« Reply #10 on: October 09, 2007, 07:19:19 PM »
This code's pretty old actually...

This code keeps a timing out URL from timing out the webpage...

Code: [Select]
function forecastfetchUrlWithoutHanging($url,$cacheurl)
   {
   // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   $numberOfSeconds=4;   

   // Suppress error reporting so Web site visitors are unaware if the feed fails
   error_reporting(0);

   // Extract resource path and domain from URL ready for fsockopen

   $url = str_replace("http://","",$url);
   $urlComponents = explode("/",$url);
   $domain = $urlComponents[0];
   $resourcePath = str_replace($domain,"",$url);

   // Establish a connection
   $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);

   if (!$socketConnection)
       {

       $html = implode('', file($cacheurl));
       return($html);

       // You may wish to remove the following debugging line on a live Web site
       // print("<!-- Network error: $errstr ($errno) -->");
       }    // end if
   else    {
       $xml = '';
       fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
   
       // Loop until end of file
       while (!feof($socketConnection))
           {
           $xml .= fgets($socketConnection, 128);
           }    // end while

       fclose ($socketConnection);

       }    // end else

   return($xml);

   }    // end function

Then this code actually makes the HTML based on the advisory...

Code: [Select]
//import NOAA Advisory info
//data can be altered by changing the zone and county numbers
//Target data ends up in $warnscroll

$html="";

$html = fetchUrlWithoutHanging('http://www.crh.noaa.gov/showsigwx.php?warnzone=IAZ069&warncounty=IAC155');

//Get the advisory headers and put them in an array

preg_match_all('|<h3>(.*)</h3>|', $html, $headers);
$warnheaders = $headers[1];

//If there is more than one advisory, we need to set its priority
//If there aren't any advsiories... we stop here... displaying nothing

if (count($warnheaders) >= 1) {

$i = 0;
$flag = 0;
$warnscroll = "";

//First, around here tornados are the biggest danger. A warning is critical information.
//Display this one first no matter what!

while ($i < count($warnheaders)):
if (preg_match("/Tornado Warning/i", $warnheaders[$i])) { 
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="tornadowarningBox"><a href="wx4.php" style="color: #FFFFFF;"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;

//Next if there are none of the above found. Display the first warning message.

if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Warning/i", $warnheaders[$i])) { 
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="warningBox"><a href="wx4.php" style="color: #FFFFFF";><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}

//Next if there are none of the above found. Display the first watch message.

if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Watch/i", $warnheaders[$i])) { 
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="watchBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}

//Next if there are none of the above found. Display the first advisory message.

if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Advisory/i", $warnheaders[$i])) { 
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="advisoryBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}

//Next if there are none of the above found. Display the first statement message.

if ($flag == 0) {
$i = 0;
while ($i < count($warnheaders)):
if (preg_match("/Statement/i", $warnheaders[$i])) { 
$warnheaders[0] = $warnheaders[$i];
$warnscroll = '<div class="advisoryBox"><a href="wx4.php"><b><span style="text-transform: uppercase;">' . $warnheaders[0] .'</span></b> IN EFFECT FOR CARTER LAKE IOWA ... [Click here for more]</a></div><br />';
$flag = 1;
break;
}
$i++;
endwhile;
}
}

Displaying the advisory itself is simple...

Code: [Select]
<?echo $warnscroll?>
How the advisory shows up is controlled with .css code... in my main .css file... this makes it really really easy to change the appearance... no editing the PHP... just change the .css and reupload.

Code: [Select]

.warningBox {
  color: white;
  font-size: 12px;
  text-align: center;
  background-color: #FF9900;
  margin: 0 0 0 0;
  padding: .5em 0em .5em 0em;
  border: 1px dashed rgb(34,70,79);
}

.watchBox {
  color: black;
  font-size: 12px;
  text-align: center;
  background-color: #FFCC00;
  margin: 0 0 0 0;
  padding: .5em 0em .5em 0em;
  border: 1px dashed rgb(34,70,79);
}

.advisoryBox {
  color: black;
  font-size: 12px;
  text-align: center;
  background-color: #F0E68C;
  margin: 0 0 0 0;
  padding: .5em 0em .5em 0em;
  border: 1px dashed rgb(34,70,79);
}

.tornadowarningBox {
  color: white;
  font-size: 13px;
  text-align: center;
  background-color: #CC0000;
  margin: 0 0 0 0;
  padding: .5em 0em .5em 0em;
  border: 1px dashed rgb(255,255,255);
}
« Last Edit: October 09, 2007, 07:21:41 PM by carterlake »

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline MW-S_Oracle

  • Member
  • *
  • Posts: 5
Re: Active Weather Alert display
« Reply #11 on: October 24, 2007, 04:28:17 PM »
So now guys / gals how would i get this to work as a block on my site?  http://www.midwest-skywarn.com

i have it set for the top - right side named Watch / Warning Advisory but i am not sure if it is working correctly.

Thanks in advance.

 

anything