From: Matthew W. <mat...@us...> - 2005-12-27 15:33:50
|
Joey French wrote: > <http://www.weather.com/outlook/recreation/boatandbeach/weather/tenday/USSC0051> > has information relative to my location, for tide, moonlight stuff: Can > I get MH to use any of this information, like it uses Sunrise and Sunset > info from online resources? Joey, the short answer is yes, although sunrise/sunset are calculated internally by mh. Take a look at mh/code/public/weather_metar.pl. It is a module I wrote that goes out to pilot-oriented weather report sites, extracts the pertinent information and then populates mh variables that can be used elsewhere. The key to extracting information is regular expressions. Take a look at perlre (a man page that comes with perl) to get a taste of how they work. You can also search for "regular expression" and "tutorial" on the web and you'll get a lot of resources. Here is a snippet from the source of the web page that you mentioned: <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD class="dataTextBold" WIDTH="50%"> <B>Sunrise:</B></TD> <TD class="captionText" WIDTH="50%">7:21 AM</TD> </TR> <TR> <TD class="dataTextBold"> <B>Sunset:</B></TD> <TD class="captionText">5:22 PM</TD> </TR> <TR> <TD class="dataTextBold"> <B>Moonrise:</B></TD> <TD class="captionText">4:43 AM</TD> </TR> <TR> <TD class="dataTextBold"> <B>Moonset:</B></TD> <TD class="captionText">3:11 PM</TD> </TR> </TABLE> The psuedo code to extract the Moonrise would be: 1. Get the entire source code into a variable. See weather_metar.pl on how to do this. Let's assume that you get the information into $html 2. my ($moonrise)=$html=~/Moonrise:.+?(\d+:\d+ .M)/s; This may look like gibberish, but it breaks down like this: Look at the $html variable and search for "Moonrise:", then skip a minimum number of letters ".+?" until you find some digits "\d+", a colon, some other digits, a space and then any character and an M (AM or PM). The "s" at the end tells PERL to search the entire $html variable at one time, not once per line. By surrounding the pertinent information in brackets, the // operator will return an array containing only that information. We then assign that information to a newly created array containing one variable, $moonrise. Now, the fun thing about perl and regular expressions in particular is that there are many ways of doing the same thing, so don't be afraid to experiment with the regular expression. Good luck, Matt __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |