sub weatherNetworkHandler
{
$html = shift;
$type = shift;
my( @rValue ) = ();
my( $done ) = 0;
my( $cTable );
my( $cCondition, $cTemp, $cWind, $cPressure, $cVisibility, $cHumidity, $cTime, $cHumidex);
my( $fiveDay, $temp, @fiveRows, $row, @dayName, @dayImage, $entry, @dayFacts );
my( $textForecast );
my( $image, $name, $desc, $work );
my( $tableIndex, $done );
print "---------------------- WeatherNetwork Handler ----------------------\n";
# print "$html\n\n";
$cCondition = "n/a";
$cTemp = "n/a";
$cPressure = "n/a";
$cWind = "n/a";
$cHumidity = "n/a";
$cHumidex = "n/a";
## Table 12 is *usually* the time of the observations and table 13 is the obersvations
## themselves. But we will be extra smart and set a variable to this value, but check
## to see if anything extra has been inserted, if something extra has been inserted
## (determined if we can't find a "time" in the first effort), increment the value and
## repeat the process again.
if( $type =~ /current/ )
{
# We want everything from the 12th table to the 13th one .... to get the
# current conditions ...
# TODO !!!
# Conditions ...
# Sometimes this seems to be table 15, 12 or 11 ... must figure out how to tell which one.
$tableIndex = 5;
$done = 0;
while( !$done )
{
$tableIndex++;
$cTable = zUtil::getNthItemNew( $tableIndex, $html, "
" );
if( $cTable =~ /[0-9]+:[0-9]+[a-z]/i ||
$tableIndex++ > 20 )
{
$done = 1;
}
}
print "Found: $cTable\n";
## We should have exited the while loop with $cTable as the observation time ...
$cTime = zUtil::getNthItemNew( 3, $cTable, "" );
$cTime = zUtil::getNthItemNew( 1, $cTime, "", "" );
if( $cTime =~ /(.*)\s*?\-/i )
{
$cTime = $1;
}
$tableIndex++; # one more than the observation time
$cTable = zUtil::getNthItemNew( $tableIndex, $html, "" );
# This is the current conditions in text
$cCondition = zUtil::getNthItemNew( 2, $cTable, "" );
$cCondition =~ s/\<.+?\>//gs;
$cCondition =~ s/\ \;//gs;
$cCondition =~ s/^\s*//gs;
print "conditions: $cCondition\n";
#exit;
$tableIndex++; # one more than the observation time
$cTable = zUtil::getNthItemNew( $tableIndex, $html, "" );
print "details: $cTable\n";
$tableIndex = 1;
# $work = zUtil::getNthItemNew( $tableIndex, $cTable, "" );
$work = zUtil::getNthItemNew( $tableIndex, $cTable, "" );
while( !($work =~ /^$/) )
{
#print "item ...: ------->$work<-------\n";
# exit;
if( $work =~ /Temperature/si )
{
$cTemp = zUtil::getNthItemNew( 3, $work, "" );
$cTemp =~ s/\<.+?\>//gs;
$cTemp =~ s/\ \;//gs;
$cTemp =~ s/^\s*//gs;
print "Temp: $cTemp\n";
}
if( $work =~ /Wind/si )
{
$cWind = zUtil::getNthItemNew( 3, $work, " | " );
$cWind =~ s/\<.+?\>//gs;
$cWind =~ s/\ \;//gs;
$cWind =~ s/^\s*//gs;
print "Wind: $cWind\n";
}
if( $work =~ /Humidity/si )
{
$cHumidity = zUtil::getNthItemNew( 3, $work, " | " );
$cHumidity =~ s/\<.+?\>//gs;
$cHumidity =~ s/\ \;//gs;
$cHumidity =~ s/^\s*//gs;
print "Humidity: $cHumidity\n";
}
if( $work =~ /Barometric/si )
{
$cPressure = zUtil::getNthItemNew( 3, $work, " | " );
$cPressure =~ s/\<.+?\>//gs;
$cPressure =~ s/\ \;//gs;
$cPressure =~ s/^\s*//gs;
print "Pressure: $cPressure\n";
}
if( $work =~ /Humidex/si ||
$work =~ /Windchill/si )
{
$cHumidex = zUtil::getNthItemNew( 3, $work, " | " );
$cHumidex =~ s/\<.+?\>//gs;
$cHumidex=~ s/\ \;//gs;
$cHumidex =~ s/^\s*//gs;
print "Humidex: $cHumidex\n\n";
}
$tableIndex++;
#$work = zUtil::getNthItemNew( $tableIndex, $cTable, "" );
$work = zUtil::getNthItemNew( $tableIndex, $cTable, "" );
}
push @rValue, { 'cCond' => $cCondition,
'cTemp' => $cTemp,
'cPressure' => $cPressure,
'cWind' => $cWind,
'cHumidity' => $cHumidity,
'cHumidex' => $cHumidex
};
}
#exit;
return reverse @rValue;
}
return 1;
| | |