Weather-Watch.com
March 12, 2010, 06:13:28 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Members: 9,363  Posts: 346,232  Topics: 38,375
Please welcome jasonprice2, our newest member.

Latest versions: WD - 10.37P  WDL - 6.05  MML - 1.03
 News:
Check out the new FAQs (Frequently Asked Questions) board for a growing list of hints, tips and diagnostic suggestions.
  Advanced Search
   Home   Bug Tracker Photo Gallery Wiki Chat Calendar Search Login Register Help  
Pages: [1]
  Print  |  « previous  |  next »  |  Go Down  
Author Topic: NWS Weather Forecast Messenger PHP Script  (Read 2882 times)
0 Members and 1 Guest are viewing this topic.
MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« on: July 10, 2009, 08:13:27 AM »

NWS Weather Forecast Messenger PHP Script by Mike Challis

Version: 1.00 - 10-Jul-2009 - release

Version: 1.01 - 10-Jul-2009 - fixed flood filter (do not use version 1.00)

Version: 1.02 - 10-Jul-2009 - added features: selectable temp units setting.
- if twitter message is too long, attempts to shorten it by abbreviating some weather condition words.
- prints on the web page how long the flood filter is still in effect for...
(Flood filter is in effect for 5 hours, 9 minutes, no twitter was sent)

Version: 1.04 - 22-Jul-2009 - added post authentication feature.

Version: 1.06 - 15-Aug-2009
- added email Bcc feature
- improved instructions inside readme.txt

Partially based on a variation of the following scripts:
NOAA Top Weather Advisory Alerter PHP Script by Mike Challis
http://www.642weather.com/weather/scripts-noaa-top-weather-alerter.php
RSS Top Warning PHP Script by Ken True http://saratoga-weather.org/scripts.php
PHP NOAA Advisory Text by Tom Chaplin http://www.carterlake.org/weatherphp.php
Twitter Code by http://morethanseven.net/2007/01/20/posting-to-twitter-using-php/
Forecast code based on http://jivebay.com/2008/04/08/free-weather-forecast/

What does it do?
This PHP script is used to check the NOAA Weather XML Forecast feeds on a timed schedule,
then send a forecast message.
Uses the forecast for the the latitude longitude you have set in the settings.
The forecast message is short enough to send to twitter, a cell phone, blackberry, or email.
Supports sending messages by Email and Twitter, each method can be enabled or disabled.
Messages can be customized in the script settings.

Includes some of the features of the NOAA Top Weather Advisory Alerter PHP Script
http://www.642weather.com/weather/scripts-noaa-top-weather-alerter.php

What do I need?
PHP 5 with CURL support is required
.. Web server hosting account with PHP support and ability to send emails from PHP
.. Ability to schedule a cron job or a scheduler program on your PC that can request a URL every 6 hours.
.. your PHP server MUST allow PHP scripts permission to write files.
... PHP safe_mode is recommended to be off

How to use it:
1) Set your settings in the "settings" of the PHP script.
Be sure to set the latitude, longitude, twitter user password and your email address.
Also set the settings for Email and Twitter to customize the messages, each method can be enabled or disabled.

2) Upload this php file to your web server

4) Test from a URL, see if you can see the HTML output
Example: http://www.yoursite.com/nws-forecast-messenger.php
After testing move it to a private non-public web server folder.
Warning: it is recommended that you put the PHP file in a non-public www directory!
because you do not want people clicking the URL and flooding you with emails and twitters!!
If you put it in a non-public www directory, then the only way you can call it is from a cron job
There is a flood filter setting that will prevent the flood problem, but make you should test it,
don't just "set it and forget it".

5) It is recommended that you test an email or twitter to make sure you will receive one.

6) Schedule automatic timed updates (see readme.txt)

Download      
www.642weather.com/weather/scripts/nws-forecast-messenger.zip

Live Demo    
www.642weather.com/weather/nws-forecast-messenger.php

My Twitter
http://twitter.com/642weather
« Last Edit: August 16, 2009, 05:37:32 AM by MCHALLIS » Logged

MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« Reply #1 on: July 10, 2009, 08:35:49 AM »

Version: 1.01 - 10-Jul-2009 - fixed flood filter (do not use version 1.00)
Logged

Budgie
Martin
Junior Weather Controller
****
Offline Offline

Location: Isle of Lewis, Scotland
Station Type: Davis VP2 with Solar, UV & FARS, Boltek PCI, Nexstorm, Logitech Pro5000 & WXSim
Posts: 3,285
Local Time: Friday 19:13


MML Station: WD00934 CWOP: CW7959


WWW
« Reply #2 on: July 10, 2009, 08:48:07 AM »

Live demo URL needs a "/weather" removed Mike.  Wink
Logged

MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« Reply #3 on: July 11, 2009, 03:51:01 AM »

Version: 1.02 - 10-Jul-2009 - added features: selectable temp units setting.
- if twitter message is too long, attempts to shorten it by abbreviating some weather condition words.
- prints on the web page how long the flood filter is still in effect for...
(Flood filter is in effect for 5 hours, 9 minutes, no twitter was sent)

Version: 1.03 - 14-Jul-2009 - fixed possible fatal error regarding attributes
« Last Edit: July 23, 2009, 12:57:04 AM by MCHALLIS » Logged

MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« Reply #4 on: July 22, 2009, 09:31:28 PM »

Version: 1.04 - 22-Jul-2009 - added post authentication feature.
Now you can edit your cron job to use CURL and pass a username and password
so that the script can be in public view and it only emails when called from your cron job with the correct username and password.
This is the best way to allow the script to be in public and have the most accurate cron times, such as I use: every 6 hours (3,9,16,22) 3pm,9pm,3am,9am
This is a sample of my cron: (be sure to set your_username and your_password)
curl -d 'username=your_username&password=your_password' http://www.642weather.com/weather/nws-forecast-messenger.php >/dev/null 2>&1  

Version: 1.05 - 22-Jul-2009
- added configurable array of shorten_message words to settings.

- shorten_twitter function changed to a shorten_message function that can shorten emails and twitters
- added two more settings:
// number of characters to attempt to shorten email message to
$email_shorten = '120';

// number of characters to attempt to shorten twitter message to
$twitter_shorten = '140';   
« Last Edit: July 23, 2009, 01:09:01 AM by MCHALLIS » Logged

MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« Reply #5 on: July 31, 2009, 04:35:16 PM »

I figured out how to send my tweets to Facebook. This is how:
Log into Facebook and go to this app:
http://www.facebook.com/selectivetwitter
Click settings and add your Twitter username, then grant permissions.
End a tweet with #fb when you want it to update your Facebook status - simple.

I made a Facebook page for 642weather, then made a personal profile for myself, I am the admin of the page now.
Pages and profiles are two different things.

http://www.facebook.com/pages/Long-Beach-Weather-Long-Beach-Washington-98631-USA/102474670891?ref=nf
Logged

MCHALLIS
Rain Maker
***
Offline Offline

Location: Long Beach, WA USA
Station Type: Davis VP2+
Posts: 1,975
Local Time: Friday 12:13



WWW
« Reply #6 on: August 16, 2009, 05:37:48 AM »

Version: 1.06 - 15-Aug-2009
- added email Bcc feature
- improved instructions inside readme.txt
Logged

fleegs79
Newbie

Offline Offline

Station Type: Davis Vantage Pro 2
Posts: 3
Local Time: Friday 18:13


WWW
« Reply #7 on: November 18, 2009, 02:07:43 AM »

Has anybody modified the script to only look at 12 hour periods?  I'd like to show a little more detail, instead of having the worst weather for the 24hr period. For example, my forecast for tomorrow shows rain likely even though it will be sunny all day and the best chance for rain is late tomorrow night.

Thanks.

Logged
fleegs79
Newbie

Offline Offline

Station Type: Davis Vantage Pro 2
Posts: 3
Local Time: Friday 18:13


WWW
« Reply #8 on: January 17, 2010, 02:56:27 PM »

If anybody is interested in using the new GeoTag API with twitter for your Forecast Tweets, modify the following function towards the bottom of the script:
Code:
function twitter_alert($twitter_message) {
 global $twitter_user, $twitter_password, $twitter_url, $user_agent, $latitude, $longitude;

  // Set up and execute the curl process
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  curl_setopt($ch, CURLOPT_URL, "$twitter_url");
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "status=$twitter_message&lat=$latitude&long=$longitude");
  curl_setopt($ch, CURLOPT_USERPWD, "$twitter_user:$twitter_password");
  $buffer = curl_exec($ch);
  curl_close($ch);

  echo '<br />';

  // check for success or failure for twitter message sending
  if (empty($buffer)) {
          echo 'WARNING: Twitter message not sent (check twitter settings)<br />';
  } else {
          echo 'A Twitter was sent:<br />';
          echo $twitter_message.'<br />';
          echo 'Twitter message length: '.strlen($twitter_message).'<br />';
  }

} // end function twitter_alert

The only changes were to the global variables and the CURLOPT_POSTFIELDS lines.  MCHALLIS, thanks for a great script.  I find it very useful.
Logged
Pages: [1]
  Print  |  « previous  |  next »  |  Go Up  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!