NWS Public Alert Messenger PHP Script

My luck sheesh! let me grab 1.07 lol

Version: 1.06 - 10-Jul-2009

Ok 1.07 is up there now!

I’m not sure why but I cannot get it to work entirely correctly.

Of course, there’s nothing for weather now to give you an example but let me try to describe.

Yesterday for example, it was saying for the em the initial special weather advisory but would not have any other details. Ie:

Subject:
Message Body:
“Alert: Special Weather Statement”

Any thoughts? The advisory text only had “Special Weather Statement” and the rss file had all the info. My goal is to have a twitter with the advisory and pertinent advisory info

Cheers and thanks!
Mike

The script only alerts about the advisory title, it does not display the contents of the alert.
Twitters cannot be more than 140 characters. If I tried to parse the contents of the “Special Weather Statement”, it would not fit in a twitter anyway.

For this reason, my twitters have a URL on them, if they click on the URL they can see the full alert on my web site.
http://twitter.com/642weather

That is one of the drawbacks of twitter. The messages are so short #-o

I had a twitter alert this morning (there was a local thunderstorm):
NWS issued: Short Term Forecast for South Washington Coast (Washington) #fb #funbeach #weather http://642weather.com

If you need short URLs for the twitter message, you can use tinyurl.com or http://bit.ly/

I installed this without a problem - a fine piece of work as always from Mike!

One little thing I noticed… A short term forecast was issued around 3:00pm MDT in the Denver area (COZ040). This was replaced with a new short term forcast at 6:47pm MDT. The script did not send out the updated short term forecast instead saying “resend timer prevention timer is in effect” in the cron log the next time it was processed.

I am guessing this is because they both had the same title? Just want to check and make sure all is well as it should be.

Thank you as always for your work!

Tony

That is working the way I designed it Tony. If the alert title is the same, it will not resend unless the resend timer is enabled and timed out.

Message Sending Activity: (No messages sent because the advisory status did not change since the last time it was checked)

Is anybody interested in a log file feature for this script?
It could append to a log file every time there is an alert.
You could include the log file in a Advisory History page.

I was thinking something like this:





Mike,

I think a log would be really cool. Would it be a running log that showed the last “X” number of alerts or something like all alerts for a week, or month, etc. and was self maintaining?

Derek

It should be self maintaining or the log would grow continuously.
Maybe it could auto purge oldest alerts after x amount of alerts are built up.
The x amount of alerts to store could be a setting that can be changed.
Also the logging feature can be enabled or disabled with a setting.

Does this sound good?
I might not do this for a few days, I have programmed so many hours this week I feel tired.
Right now, I am working on two computers at once, and writing a seminar: Internet and Computer Safety - “How to stay clear of viruses, adware, spyware, spam, and scams when using the Internet”.

Got it - thanks, Mike. I figured as much. I will just adjust the timing in the script accordingly as our local NWS oftentimes sends out three or four short term forecasts in a row, each spanning a couple of hours.

As for a log file, that might be kind of nice. Ideally it would be like you say where it gets overwritten after a period of time.

T

Mike,

I think all that sounds great.

I don’t doubt you’re tired, with what you’ve done here over the last few days alone, not to mention all the other stuff you’re doing. We all really appreciate everything but for sure you should take a break!!!

Derek

Here is a good question!

Using the script i took notice that if you are with a hosting company with the emails going out it never goes out with the correct email information. Sample say you place in the script $email_address_sent_from = ‘[email protected]’;

So when the message comes down it shows it is from [email protected]
Now they had me edit my php.ini files to have this:
sendmail_path = /usr/sbin/sendmail -t -i -f [email protected];

And it still with go back to [email protected]. Now one thing they said that would correct that problem is if the script used SMTP Authentication This way the email that is generated by the script would have the correct sent from email address as in [email protected].

Is there an easy way of adding that?

What host is causing all this trouble? is it windows or Linux?

First, just try this code in the settings section of the script after the $email_address_sent_from:

ini_set('sendmail_from', $email_address_sent_from); // needed for some windows servers

if that did not work, try adding this:


// OPTIONAL: You can change the default SMTP settings below...
// NOTE most servers do not need these settings changed!!!
$ctf_ini_set       = "yes";        // "yes" to enable this feature (ONLY if needed)
$ctf_smtp          = "localhost"; // sometimes mail.yourdomain.com Confirm with your host
$ctf_smtp_port     = "25";        // Confirm with your host
$ctf_smtp_username = "you";       // your mail username. If you do not know, ask your host
$ctf_smtp_password = "123456";    // your mail password. If you do not know, ask your host
$ctf_sendmail_from = "[email protected]";   // Your email
$ctf_sendmail_path = "/usr/sbin/sendmail -t -i"; // If different, ask host


if(strtolower($ctf_ini_set) == "yes") {
       ini_set("SMTP", $ctf_smtp);
       ini_set("smtp_port", $ctf_smtp_port);
       ini_set("smtp_password", $ctf_smtp_password);
       ini_set("smtp_username", $ctf_smtp_username);
       ini_set("sendmail_from", $ctf_sendmail_from);
       ini_set("sendmail_path", $ctf_sendmail_path);
}
    

let me know if it worked.

they are all Linux box’s. going to try this one in this location in the script:

<?php error_reporting(E_ALL ^ E_NOTICE); // Report all errors except E_NOTICE warnings ini_set('display_errors', 1); // turn error reporting on //ini_set('log_errors', 1); // log errors //ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); // where to log errors /* NOAA Top Weather Advisory Alerter PHP Script by Mike Challis More Info - www.642weather.com/weather/scripts-noaa-top-weather-alerter.php Download - www.642weather.com/weather/scripts/noaa-top-weather-alerter.zip Live Demo - www.642weather.com/weather/rss-weather-alerter.php Free PHP Scripts - www.642weather.com/weather/scripts.php Contact Mike - www.642weather.com/weather/contact_us.php Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642 // Mail Settings // OPTIONAL: You can change the default SMTP settings below... // NOTE most servers do not need these settings changed!!! $ctf_ini_set = "yes"; // "yes" to enable this feature (ONLY if needed) $ctf_smtp = "localhost"; // sometimes mail.yourdomain.com Confirm with your host $ctf_smtp_port = "25"; // Confirm with your host $ctf_smtp_username = "you"; // your mail username. If you do not know, ask your host $ctf_smtp_password = "123456"; // your mail password. If you do not know, ask your host $ctf_sendmail_from = "[email protected]"; // Your email $ctf_sendmail_path = "/usr/sbin/sendmail -t -i"; // If different, ask host if(strtolower($ctf_ini_set) == "yes") { ini_set("SMTP", $ctf_smtp); ini_set("smtp_port", $ctf_smtp_port); ini_set("smtp_password", $ctf_smtp_password); ini_set("smtp_username", $ctf_smtp_username); ini_set("sendmail_from", $ctf_sendmail_from); ini_set("sendmail_path", $ctf_sendmail_path); }

The above didn’t work.

That is not a good location in the script to put PHP code because that is a comment section. PHP code there is ignored.

Put it just before this:

//------------------------------------------------------------------
// end settings. Do not alter any code below this point in the script or it may not run properly.
//------------------------------------------------------------------

Just got off the phone with tech support, since i have the directory set to 600 i needed it set to 700 for owner read write and excute. also in my php.ini had spaces in there. did a test after they told me this email address seems to be working now. Helps if there are no spaces when i am editing a php.ini file huh? lol.

So now i have the directory hidden again with the correct chmod on it. so have to wait till it sends the forecast down in a few hours to see what it says, since there are no warnings that script will not do anything unless i out it in test mode. but letting the cron job run to see if the other works. if one does the other should.

Well i will check my email on my cell tomorrow if still doing the same will test it with it down there.
will let ya know!
thanks.

You can test it right now with this setting:

// set to 1 to test the script's email function (it will send a test fake alert, be sure to set it back when done)
// set to 0 for normal operation
$test_email_advisory = 1;

set it to 1, load the script in a url, check email.
set it back to zero after you test.

Erice emailed me back saying they disabled safe_mode for me. But Im still getting an error with that txt file. Should I remove that file now and see If it works without it? Thanks.

http://www.snoqualmieweather.com/rss-weather-alerter.php