Weather Display Conditions Messenger PHP Script

Thanks Ken, I added some of your code in here.

Version: 1.01 - 15-Jul-2009 - improved units of measures handling

  • added rounding of wind units
  • added settings for units of measure indicators
  • added setting for testtags file path
  • added setting for selecting one of two wind display options
  • added timestamp to message

Version: 1.02 - 15-Jul-2009 - added high/low temp to messages: (H84/L59)

Just tested this one, works fine no problems at all!

Just a side note, If you use a Davis VP 2+ and want to use the info that comes from the solar info, just replace $weathercond with $Currentsolardescription as the $weathercond is based on the metar for the airport you are using. and using the $Currentsolardescription will use the info that is coming from your unit.

the tag to replace is $weathercond :

$wxconditions = fixup_time($time)." $weathercond - Temp $sTemp$uomTemp$sHL, Wind $sWind, Baro $sBaro$uomBaro, RainToday $sRain$uomRain, Hum $sHum%";

Run a few test runs to make sure you are still under the 140 cap that twitter uses.

a sample of my output is:
2:10am Temp 68F (H 71/L 68) Night Time/Dry/Cloudy with clear patches Hum 80% Winds S 0->2mph Baro 29.88in Rain Today 0.00in

As above using the solar tag showed Night Time/Dry/Cloudy with clear patches, and using $weathercond showed only Dry.

Now using the solar here is my line i have set:

$wxconditions = fixup_time($time)."  $sTemp$uomTemp $sHL $Currentsolardescription  Hum $sHum% Winds $sWind Baro $sBaro$uomBaro Rain Today $sRain$uomRain";

Which will output like this:

1:55pm 88F (H 88/L 68) Sunny/Dry Hum 46% Winds WNW 8->16mph Baro 29.80in Rain Today 0.09in

Works well for twitter and text message to your phone.

Thanks goes to Ken and Mike for the newer script that does the twitter and email.

Thanks Albert.

I am testing a version that has an improved shorten_twitter function
http://www.642weather.com/weather/wd-conditions-messenger.php

It incorporates this setting:

// array of words to shorten, but only when the twitter message is more than 140 characters.
// array is formatted is like this: 'Long Word' => 'Short Word',
// you can add or comment out lines from this array as you like
// the shorten_twitter function will loop through the word replacements one at a time and break early
// if the message is shortened enough.
$twitter_shorten = array(
'Showers'     => 'Shwrs',
'Rain'        => 'Rn',
'Chance'      => 'Chce',
'Partly'      => 'Ptly',
'Cloudy'      => 'Cldy',
'Forecast'    => 'Frcst',
'Night Time/' => '',
'Cloudy with clear patches' => 'Ptly Cldy',
);

I switched on $Currentsolardescription my demo.
I got busy so I cannot release it today.

No problem, I was tinkering with the script till about 3am lol. Since i am a night owl all the time. and was tweaking the settings. Just have to watch for the longest one of them all i seen so far and that is the: Night Time/Dry/Cloudy with clear patches

Version: 1.03 - 17-Jul-2009 - improved shorten_twitter function

  • added configurable array of shorten_twitter words to settings.
  • changed current condition variable to use $Currentsolardescription instead of $weathercond,
    this can be reversed on about line 256:
// uncomment only one of these two condition tags
$sCond = $Currentsolardescription; // current condition: Dry/Cloudy
//$sCond = $weathercond;           // current condition: Dry

Mike works great here. Love the idea for the lines to strip anything that is above 140 for twitter.
As for the email via text to a cell phone took notice they also have a limit. So i used what you had in there and have the email set for 120 chars. So both work.

Version: 1.03 - 17-Jul-2009

OK Albert, thanks for the suggestion.

Version: 1.04 - 17-Jul-2009 - 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 twitter message to
    $twitter_shorten = ‘140’;

// number of characters to attempt to shorten email message to
$email_shorten = ‘120’;

You way was cleaner than mine lol.

Did notice that the Cloudy with clear patches still shows up. But i was working on it, when it went overcast just my luck lol. and noticed that it adds a extra space after the $sCond, so you end up with Cloudy with clear patches , Temp.

Also in the Array you have ‘Night Time/’ => ‘’, twice is this correct? wasn’t sure.
Also seen that it seems wd is adding it’s own little space in there, as i did have $sCond, in there and now with a update shows Night Time/Dry/mostly cloudy - , Temp 61F

Yea i like tinkering with things. and i am up 1/2 the night lol

The night time was in there twice because one has a capital T and one does not.

Version: 1.05 - 17-Jul-2009 - trim spaces from current conditions

ok left the script as is to check still get that extra space from wd: cloudy -, Temp

Checking the testtags.php shows: $Currentsolardescription = 'Night Time/Dry/mostly cloudy - ';

put this line in the $shorten_words_array
‘mostly cloudy -’ => ‘Cldy’,

Ok mike that works. I will keep an eye out for any of the tags and what they are. and add them in one by one. I am sure there are a few there.

Version: 1.06 - 19-Jul-2009 - added email Bcc feature

Version: 1.07 - 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 hour
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/wd-conditions-messenger.php >/dev/null 2>&1

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

Thanks, it works beautifully, and so easy.
Al

Hi Mike!
Actually this application sent weather condictions (in twitter and FB) every one hour. Is it possibile to set it every 6 hours?
Thanks in advance,

Alessandro