<?php
// All of the documentation and software included in the PHP Climate
// Release is copyrighted by Sebastien Windal
//
// Copyright 2002
// Sebastien Windal. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// This product includes software developed by Sebastien Windal and their
// contributors.
// 4. Neither my name nor the names of its contributors may be used to
// endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
include_once "data_collect.php";
include_once "convertissor.php";
class weather_com_data_collector extends data_collector
{
//--------------------------------------------------------------------
//Constructor
function weather_com_data_collector($root_url, $metric) {
$this->data_collector(HTTP, $root_url, $metric);
}
//--------------------------------------------------------------------
//Public methods
function get_raw_data_from_zip($zip) {
$request = "/outlook/health/climatology/monthly/".
$zip;
$this->get_raw_data($request);
}
function get_clim_data_from_raw_data() {
$weather = array('maxtemp' => array(),
'mintemp' => array(),
'meantemp' => array(),
'precip' => array());
//$state used by the simple state machine. Basicaly we have 3
//temperatures to read followed by a precipitation height.
$state = 0;
//Read the buffer line by line. When we find a temperature
//or precipitation height, push it into the result array...
$tok = strtok($this->raw_data, "\n");
while ($tok) {
if (ereg ("(-?[0-9.\]+)(°F<| in)", $tok, $regs)) {
switch($state++) {
case 0:
$temp = $regs[1];
if ($this->metric == "true")
convertissor::conv_to_C($temp);
array_push($weather['maxtemp'], $temp);
break;
case 1:
$temp = $regs[1];
if ($this->metric == "true")
convertissor::conv_to_C($temp);
array_push($weather['mintemp'], $temp);
break;
case 2:
$temp = $regs[1];
if ($this->metric == "true")
convertissor::conv_to_C($temp);
array_push($weather['meantemp'], $temp);
break;
case 3:
$pre = $regs[1];
if ($this->metric == "true")
convertissor::conv_to_mm($pre);
array_push($weather['precip'], $pre);
break;
} //switch
if ($state > 3)
$state = 0;
} //if
$tok = strtok("\n");
} //while
return $weather;
} //function
}