|more useful options|
Weather Forecasts emailed to cell phoneby davido (Archbishop)
|on Jul 01, 2004 at 04:43 UTC||Need Help??|
Ok, this is a wierd one, but I thought it was worth sharing anyway.
Some of you know that I enjoy sailing. The problem is you really never know when you'll get that urge to drop everything and go down to the marina. Sometimes this will happen at times when an immediate weather forecast isn't readily available. And in sailing, weather is important.
Sure, I could drive down to the marina and turn on the weather radio, or tune in the station on the car stereo, but where's the fun in that?
This script is the answer. I have set up a procmail filter that intercepts email messages sent from my AT&T Wireless cell phone to a particular email address. If the message has in its subject: "Forecast", and in its body a city, and a state abbreviation, the filter invokes the following script.
The script then goes to the NOAA website, grabs the forecast for the city in question (including storm warnings if there are any), and sends off a series of email messages back to my cellphone.
For testing purposes, if the script is not given an email address to respond to, it will just print the output.
Here's the tricky part. AT&T Wireless truncates email messages at 120 characters. So this script does its best to try to abbreviate most of the words in the forecast. The output takes a little getting used to, but almost always fits into 120 characters per day. The script sends one email per day, and one per storm-warning. So if you run it with an email address, it'll spew out six or more 120 character messages, each representing one day's worth of forecast, plus however many messages it takes to communicate any relevant storm warnings.
The usage is as follows:
First, using the defaults:
This will give you the forecast for Los Angeles, CA. You can also invoke the script like this:
...in which case, it will give you the forecast for the city and state you've specified.
If you want to supply an email address, you may also do that:
And finally, for you windows folks (myself included), you may specify a mailhost to use for a direct SMTP mailing:perl weather.pl "Los Angeles" "CA" "firstname.lastname@example.org" "mail.yourhost.com"
If you don't want to bother with all the work of setting up an email filter to invoke the script, you may just set it up in a cron job or a Windows Scheduler job to have the forecast sent to your mobile device once every 24 hours.
If you're one of the lucky people whos cell phone carrier doesn't truncate messages at 120 characters, you should be able to easily modify the script to send everything at once, in one single email. ...not too difficult.
This is mostly a proof of concept for myself, and something that I just wanted to play with. I wanted to try out the Geo::WeatherNOAA. I hope it sparks some ideas out there... Here's the code:
I've found that the NOAA website is kind of finacky about its forecast cities. I had to fiddle a bit to find which cities work and which don't. For example, for some reason, Oxnard, CA doesn't work.
Comments are welcomed; I'm always interested in sharpening my skills.