Weather Forecast Action


What

Use

Installation

Code
<?php
// wxforecast
// Parses standard NOAA Zone forecasts.
// The forecast files must be downloaded to $zonedir on your system via some other means

$zonedir = "/usr/wx/Zones/";
$aforecast = file($zonedir . $zone . ".txt");
$days = array();
$daycount = 0;
$done = 0;
$foundzone = 0;
$limitdays = 0;
if(isset($daylist)) {
    $adaylist = explode(",",$daylist);
    $limitdays = 1;
}

foreach($aforecast as $fline) {
    // Check for stopper "&&" at start of line
    if(ereg("^\&\&.*",$fline)) {
        $done = 1;
    }

    // If stopper found, ignore rest of line
    if($done) {continue;}

    // Look for timestamp
    if(ereg("^[0-9]+ (AM|PM) (PST|PDT) (...) (...) (.*)",$fline,$match)) {
        $zonedate = $match[0];
        $foundzone = 0;
        continue;
    }

    // Look for zone id
    if(ereg("^" . $zone . "-.*",$fline)) {
        $foundzone = 1;
        continue;
    }

    if($foundzone) {
        $zonename = $zonename . ' ' . $fline;
    }

    // Look for start of day tag (. at start of line)
    if(ereg("^\.([^\.]*)\.\.\.(.*)",$fline,$match)) {
        $day = $match[1];
        $fcast = $match[2];
        $days[$day] = $fcast;
        echo "\n";
    } else {
        if($day != '') {
            $days[$day] = $days[$day] . ' ' . $fline;
        }
    }
}


echo "<div class='wx'><table cellspacing='0'>";
echo "<tr><th colspan='2'>$zonedate<br />$zonename</th><tr>\n";
echo "<tr><th>Day</th><th>Forecast</th></tr>\n";
foreach($days as $dayid=>$fcast) {

    if($limitdays) {
        if(in_array($dayid,$adaylist)) {
            echo "<tr><td id='day'>$dayid</td><td id='fcast'>$fcast</td></tr>\n";
        }
    } else {
        echo "<tr><td id='day'>$dayid</td><td id='fcast'>$fcast</td></tr>\n";
    }
}
echo "</table></div>\n";

?>


CSS Updates
Put this in your active CSS file. Change style as you see fit
.wx table {
padding: 0 0 0 0;
border: 1px solid #000;
width: 100%;
text-align: left;
}

.wx tr {
background-color: #FFFFAF;
font: 10pt sans-serif;
color: blue;
border-bottom: 1px dotted #888;

}

.wx th {
padding: 4px 0 8px 4px;
border-bottom: 1px solid #000;
text-align: center;
}


.wx td {
background-color: #F9FFFF;
font: 8pt sans-serif;
color: black;
vertical-align: top;
border-bottom: 1px dotted #888;
border-right: 1px dotted #888;
padding: 4px 0 2px 8px;
}


Example of raw forecast data
Expires:200703300130;;935450
FPUS56 KSTO 291022
ZFPSTO
INTERIOR NORTHERN CALIFORNIA ZONE FORECASTS
NATIONAL WEATHER SERVICE SACRAMENTO CA
330 PDT THU MAR 29 2007
SPOT TEMPERATURES AND PROBABILITIES OF MEASURABLE PRECIPITATION
ARE FOR TODAY...TONIGHT...AND FRIDAY.
CAZ017-300130-
SOUTHERN SACRAMENTO VALLEY-
INCLUDING THE CITIES OF...SACRAMENTO 
330 AM PDT THU MAR 29 2007
.TODAY...SUNNY. HIGHS AROUND 75. NORTHWEST WINDS 5 TO 15 MPH. 
.TONIGHT...MOSTLY CLEAR. LOWS 40 TO 45. LIGHT WINDS. 
.FRIDAY...MOSTLY SUNNY. HIGHS 73 TO 76. SOUTH WINDS UP TO 10 MPH. 
.FRIDAY NIGHT...MOSTLY CLEAR. LOWS AROUND 44. SOUTHWEST WINDS UP
TO 10 MPH. 
.SATURDAY...PARTLY CLOUDY. HIGHS AROUND 72. SOUTHWEST WINDS UP TO
10 MPH. 
.SATURDAY NIGHT...PARTLY CLOUDY. LOWS AROUND 44. 
.SUNDAY...PARTLY CLOUDY. HIGHS AROUND 70. 
.SUNDAY NIGHT...PARTLY CLOUDY. LOWS AROUND 42. 
.MONDAY THROUGH WEDNESDAY...MOSTLY CLEAR. HIGHS AROUND 72. LOWS
AROUND 42. 
&&
		TEMPERATURE  /  PRECIPITATION 
SACRAMENTO             76   44   75  /   0    0    0 
SAC EXEC AIRPORT       74   42   74  /   0    0    0 
=
$$


To Do


There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki