rendered paste body<?php
class mWeather
{
function Weather($username, $location)
{
// !weather help == "Find the Weather for any City, State or ZIP Code, or Airport Code or Country. Syntax: !weather <location> Example: !weather brisbane, australia"
if (false)
{
mFunction::commandSend("PRIVMSG $username The number of queries must be from 1 to 9.");
}
else
{
$found = false;
// mFunction::commandSend("PRIVMSG $username ".chr(2).chr(3)."4Location: '$location' | URLGen: http://www.google.com/search?q=$location".chr(2).chr(3));
if (true)
{
$num = 1; // this line sets it to get three query
}
echo "\nNum: $num\n";
$query = urlencode(trim($location));
echo "Query: $query\n\n<br>";
$sock = @fsockopen("www.wunderground.com",80,$errstr,$errno,20); // this line creates a socket on $sock
if(!$sock)
{
die("ERROR: Socket faild to connect."); // this dies if the socket doesnt connect right
}
fwrite($sock, "GET /cgi-bin/findweather/getForecast?query=".$query." HTTP/1.1\r\n"); // this sents the GET HTTP command
fwrite($sock, "Host: www.wunderground.com\r\n"); // this sends the HOST http command
fwrite($sock, "Connection: Close\r\n\r\n"); // this sends to close the connection (HTTP COMMAND)
while(!feof($sock))
{
$rawhtml .= fgets($sock); // this line adds to $rawhtml (.= means to ADD to a variable, not overwrite it) while the connection is still present
}
if ($Search = strstr($rawhtml, "<h1>Search Results:</h1>"))
{
echo "Multiple Options Found.<br>\n\r";
$found = 2;
$result = strstr($rawhtml, '<table class="boxB"');
$antiResult = strstr($rawhtml, '<a name="legend">');
$result = str_replace($antiResult, "", $result);
$rowTracker = 'class="rowW"';
$rowSpliter = 'html">';
$rowTerminator = '<';
$results = explode($rowTracker, $result);
echo "Count: ".count($results);
$maxKey = 0;
foreach ($results as $key => $place)
{
if ($key == 0)
{
}
else
{
$key = $key - 1;
$place = substr(strstr($place, $rowSpliter),6);
$antiSpliter = strstr($place, $rowTerminator);
$place = str_replace($antiSpliter, "", $place);
$maxKey = $key;
$results[$key] = trim($place);
// echo "Place $key: $place<br>\r\n";
}
}
unset($results[(count($results) - 1)]);
echo "MaxKey: $maxKey";
print_r($results);
//echo $result;
$Message = "PRIVMSG $username Search Results for '$location': ";
$rows = (ceil((count($results) / 5)) - 1);
for($inc = 0; $inc <= $rows; $inc++)
{
$offset = ($inc * 5);
$x = $offset;
while($x < ($offset + 5))
{
$Message .= " $results[$x]";
$x++;
}
mFunction::commandSend("PRIVMSG $username $Message");
}
}
else
{
echo "Location Found.<br>\n\r";
$found = 1;
/* // Location Parse
$Place = substr(strstr($rawhtml, "<h1>"),4);
$antiPlace = strstr($Place, "</h1>");
$Place = str_replace($antiPlace, "", $Place);
// -----
// Time Parse
$timeSplit = 'Local Time:</td>';
$timeStart = '<b>';
$timeEnd = '</b>';
$time = str_replace(strstr(substr(strstr(strstr($rawhtml, $timeSplit), $timeStart), 3), $timeEnd), "", substr(strstr(strstr($rawhtml, $timeSplit),$timeStart), 3));
// echo "Time: $time";
// -----
// Temperature Parse
$temp = explode('<nobr>', $rawhtml, 4);
unset($temp[0],$temp[1]);
$temp[2] = strip_tags(str_replace(strstr($temp[2], '</nobr>'), "", $temp[2]));
$temp[3] = strip_tags(str_replace(strstr($temp[3], '</nobr>'), "", $temp[3]));
$temp = $temp[2]." | ".$temp[3];
// print_r($temp);
// -----
// Condition Parse
$condStart = '<div id="b" style="font-size: 14px;">';
$condEnd = '</div>';
$cond = str_replace(strstr(substr(strstr($rawhtml, $condStart), 37), $condEnd), "", substr(strstr($rawhtml, $condStart), 37));
// echo "cond: $cond";
// -----
// Humidity Parse
$humidSplit = 'Humidity:';
$humidStart = '<nobr><b>';
$humidEnd = '</b>';
$humid = str_replace(strstr(substr(strstr(strstr($rawhtml, $humidSplit), $humidStart), 9), $humidEnd), "", substr(strstr(strstr($rawhtml, $humidSplit),$humidStart), 9));
// echo "humid: $humid";
// -----
// Wind Parse
$windSplit = 'Wind:';
$windStart = 'metric="km/h">';
$windEnd = '</span>';
$wind = str_replace(strstr(substr(strstr(strstr($rawhtml, $windSplit), $windStart), 14), $windEnd), "", substr(strstr(strstr($rawhtml, $windSplit),$windStart), 14));
// echo "wind: $wind";
// -----
// Pressure Parse
$pressSplit = '>Pressure:';
$pressStart = '<b>';
$pressEnd = '</span>';
$press = strip_tags(str_replace(strstr(substr(strstr(strstr($rawhtml, $pressSplit), $pressStart), 3), $pressEnd), "", substr(strstr(strstr($rawhtml, $pressSplit),$pressStart), 3)));
// echo "press: $press";
// -----
// Visibility Parse
$visibSplit = '>Visibility:';
$visibStart = '<b>';
$visibEnd = '</td>';
$visib = strip_tags(str_replace(strstr(substr(strstr(strstr($rawhtml, $visibSplit), $visibStart), 3), $visibEnd), "", substr(strstr(strstr($rawhtml, $visibSplit),$visibStart), 3)));
// echo "visib: $visib";
// -----
// UV Parse
$uvSplit = 'UV:';
$uvStart = '>';
$uvEnd = '</span>';
$uv = strip_tags(str_replace(strstr(substr(strstr(strstr($rawhtml, $uvSplit), $uvStart), 1), $uvEnd), "", substr(strstr(strstr($rawhtml, $uvSplit),$uvStart), 1)));
// echo "uv: $uv";
// -----
// Cloud Parse
$cloudSplit = 'Clouds:';
$cloudStart = '<b>';
$cloudEnd = '<div';
$cloud = strip_tags(str_replace(strstr(substr(strstr(strstr($rawhtml, $cloudSplit), $cloudStart), 1), $cloudEnd), "", substr(strstr(strstr($rawhtml, $cloudSplit),$cloudStart), 1))). " (Above ground level)";
// echo "cloud: $cloud";
// ----- */
// FORCAST PARSING
// FORCAST -> Day Title Parse
$forcast = explode('<tr class="taC">', strstr($rawhtml, "5-Day Forecast"));
$forcastTemps = explode('<div id="b" style="white-space: nowrap;">', $forcast[2]);
$days = explode('<td style="width: 20%;">', $forcast[1]);
unset($forcast, $days[0]);
$x = 0;
foreach ($days as $key => $day) // 1,3, 4,6
{
$offset = ($x * 2);
$day = strip_tags($day);
if ($x == 5)
{
$forcastTemp = $forcastTemps[($x + 1)];
$$forcastTemp = str_replace(strstr($forcastTemp, '</div>'), "", $forcastTemp);
}
else
{
$forcastTemp = explode('">',$forcastTemps[($x + 1)]);
$forcastTemp_1 = str_replace(strstr($forcastTemp[1], "<"), "", $forcastTemp[1]);
$forcastTemp_2 = str_replace(strstr($forcastTemp[3], "<"), "", $forcastTemp[3]);
$forcastTemp_3 = str_replace(strstr($forcastTemp[4], "<"), "", $forcastTemp[4]);
$forcastTemp_4 = str_replace(strstr($forcastTemp[6], "<"), "", $forcastTemp[6]);
$forcastTemp = $forcastTemp_1." | ".$forcastTemp_2. " |-:-| ".$forcastTemp_3." | ".$forcastTemp_4;
// echo "<br><br>\n\rBANG: $BANG<br><br>\n\r";
}
$forcast[$day] = array('temp' => $forcastTemp, 'cond' => $forcastCond, 'percip' => $forcastPercip);
$x++;
}
// FORCAST -> Data Parse
print_r($forcast);
// print_r($forcast[3]);
}
// echo $rawhtml;
$definition = explode("<div class=g>",$rawhtml); // this like explodes (seperates on <a class=l href="
//echo "\n\n" . print_r($definition) . "\n\n";
/*
$weather = strstr($rawhtml, "<p class=g>");
$subWeather = strstr($weather, "<div class=g>");
$weather = str_replace($subWeather, "", $weather);
$stuff = explode("<br>", $weather);
// echo $weather;
// print_r($stuff);
$location = strip_tags($stuff[0]);
$temp = strip_tags($stuff[1]);
$condition = strip_tags($stuff[2]);
$wind = strip_tags($stuff[3]);
$moisture = explode("</font>",$stuff[4],2);
$moisture = $moisture[0];
$day1_name = strip_tags(substr(strstr($stuff[4],">"),1));
list($day1_high,$day1_low,$day2_name) = explode(" | ",$stuff[6],3);
$day1_forcast = str_replace(strstr(substr(strstr(strstr($stuff[5], 'alt="'), '"'),1), '"'), "", substr(strstr(strstr($stuff[5], 'alt="'), '"'),1));
$day2_name = substr(strstr(strip_tags($day1_low),";"),1);
list($day2_high,$day2_low,$day3_name) = explode(" | ",$stuff[8],3);
$day2_forcast = str_replace(strstr(substr(strstr(strstr($stuff[7], 'alt="'), '"'),1), '"'), "", substr(strstr(strstr($stuff[7], 'alt="'), '"'),1));
$day3_name = substr(strstr(strip_tags($day2_low),";"),1);
list($day3_high,$day3_low,$day4_name) = explode(" | ",$stuff[10],3);
$day3_forcast = str_replace(strstr(substr(strstr(strstr($stuff[9], 'alt="'), '"'),1), '"'), "", substr(strstr(strstr($stuff[9], 'alt="'), '"'),1));
$day4_name = substr(strstr(strip_tags($day3_low),";"),1);
list($day4_high,$day4_low) = explode(" | ",$stuff[12],2);
$day4_forcast = str_replace(strstr(substr(strstr(strstr($stuff[11], 'alt="'), '"'),1), '"'), "", substr(strstr(strstr($stuff[11], 'alt="'), '"'),1));
$low1 = substr(strstr($day1_low, ";"),1);
$low2 = str_replace(substr(strstr($day1_low, ";"),1), "", $day1_low);
$forcast = array("first" =>
array("name" => strip_tags($day1_name), "high" => strip_tags($day1_high), "low" => str_replace(substr(strstr($day1_low, ";"),1), "", $day1_low), "condition" => strip_tags($day1_forcast)),
"second" =>
array("name" => strip_tags($day2_name), "high" => strip_tags($day2_high), "low" => str_replace(substr(strstr($day2_low, ";"),1), "", $day2_low), "condition" => strip_tags($day2_forcast)),
"third" =>
array("name" => strip_tags($day3_name), "high" => strip_tags($day3_high), "low" => str_replace(substr(strstr($day3_low, ";"),1), "", $day3_low), "condition" => strip_tags($day3_forcast)),
"forth" =>
array("name" => strip_tags($day4_name), "high" => strip_tags($day4_high), "low" => str_replace(substr(strstr($day4_low, ";"),1), "", $day4_low), "condition" => strip_tags($day4_forcast)),
);
print_r($forcast);
echo " <br>Location: ".$location." <br>\r\nTemp: ".$temp."<br>\r\nCondition: ".$condition." <br>\r\nWind: ".$wind." <br>\r\nMoisture: ".$moisture." <br><br>Data:<br>".$day1_forcast." <br>Name: "
.strip_tags($day1_name)." <br>High: ".$day1_high." <br>Low: ".$day1_low." <br>Forcast: ".$day1_forcast." <br>Day2: "
.strip_tags($day2_name)." <br>High: ".$day2_high." <br>Low: ".$day2_low." <br>Forcast: ".$day2_forcast." <br>Day3: "
.strip_tags($day3_name)." <br>High: ".$day3_high." <br>Low: ".$day3_low." <br>Forcast: ".$day3_forcast." <br>Day4: "
.strip_tags($day4_name)." <br>High: ".$day4_high." <br>Low: ".$day4_low." <br>Forcast: ".$day4_forcast;
*/
for($i=1;$i<=$num;$i++)
{ // this counts down hwo many there are
// $defParam = explode("<font size=-1>", $definition[$i]);
// $title = html_entity_decode(strip_tags($defParam[0]),ENT_QUOTES);
// $defParam2 = explode("<br>", $defParam[1]);
// $summary = html_entity_decode(strip_tags($defParam2[0]),ENT_QUOTES);
// echo "Def Param: ".print_r($defParam2);
if (strlen($summary) > 40)
{
$x = 0;
$sumAry = array();
while ($sumAry[$x] > 40)
{
$sumAry[$x] = substr($summary, ($x * 40), 40)."\r\n";
$x++;
}
//$summary = implode("\r\n", $sumAry);
}
}
}
}
}
mWeather::Weather("USERNAME", "monroe, wa");
?>