section ;-) // // TIP - Get noaarec.php?noaabug working BEFORE you commit to modifying dashboard // there have been several cases where a previous 'include' changed TZ to UTC // If this happens 'include' noaarec.php higher up the page OR uncomment and set TZ BELOW // date_default_timezone_set("America/??????????"); date_default_timezone_set("America/Mexico_City"); $wfo = "bis"; $sid = "bis"; $showNoaaAvg = true; // Like it says display max avg / min avg [true / false] // Only used in html patch which has a 'switch' // **** NO USER VARS BELOW THIS LINE ****************************************** // Belts 'n' braces - preset important vars $thisDayMax = $thisDayMax1 = $thisDayCacheMax = $thisDayCacheMax1 = null; $thisDayMaxYear = $thisDayMaxYear1 = $thisDayCacheMaxYear = $thisDayCacheMaxYear1 = null; $thisDayMin = $thisDayMin1 = $thisDayCacheMin = $thisDayCacheMin1 = null; $thisDayMinYear = $thisDayMinYear1 = $thisDayCacheMinYear = $thisDayCacheMinYear1 = null; $thisDayMaxAvg = $thisDayMaxAvg1 = $thisDayCacheMaxAvg = $thisDayCacheMaxAvg1 = null; $thisDayMinAvg = $thisDayMinAvg1 = $thisDayCacheMinAvg = $thisDayCacheMinAvg1 = null; $bugout = $bugout2 = $bugout3 = ""; $noaagrab = false; $doTomorrow = false; $all = false; echo "\n\n"; if(isset($_REQUEST['noaabug'])) { $noaabug = true; } else { $noaabug = false; } $err = false; if($noaabug) { echo "
\n"; echo (file_exists("noaarecdat.txt")? "noaarecdat was previously: " . date ("l jS \of F Y h:i:s A T", filemtime('noaarecdat.txt'))."
\n" : "noaarecdat.txt was NOT found
\n"); echo "Local Server Time NOW: " .date('l jS \of F Y h:i:s A T, e - \U\T\C\ P')."
\n";
echo "\$wfo = $wfo
\n \$sid = $sid
\n"; } $check_it = time() - (60 * 60); // 1hr ago - only used when no 'tomorrow' data, or missing data $serverDay = date('j'); $tomorrow = date('j',strtotime('tomorrow')); // initial age check of cache is unimportant - it's the contents that matter !!! // include cachefile here for check purposes - a LOT of belt 'n' braces $tod = $tom = ""; if($test = @file_get_contents("noaarecdat.txt")) { // set valid date vars from cache, code is mostly debug ! $mimi = 0; $test = explode("\n", $test); foreach($test as $v) { $check = explode(",", $v); if($check[0] == $serverDay) { echo "\n\n"; $tod = "
server day found in cache $test[$mimi]
\n";
if(in_array("", $check)) $noaagrab = true; // at least one value missing
if($check[1]) {
$thisDayCacheMax = $check[1];
} else {
echo "\n";
$tod .= "thisDayMax MISSING
\n";
}
if($check[2]) {
$thisDayCacheMaxYear = $check[2];
} else {
echo "\n";
$tod .= "thisDayMaxYear MISSING
\n";
}
if($check[3]) {
$thisDayCacheMin = $check[3];
} else {
echo "\n";
$tod .= "thisDayMin MISSING
\n";
}
if($check[4]) {
$thisDayCacheMinYear = $check[4];
} else {
echo "\n";
$tod .= "thisDayMinYear MISSING
";
}
if($check[5]) {
$thisDayCacheMaxAvg = $check[5];
} else {
echo "\n";
$tod .= "thisDayMaxAvg MISSING
\n";
}
if($check[6]) {
$thisDayCacheMinAvg = $check[6];
} else {
echo "\n";
$tod .= "thisDayMinAvg MISSING
\n";
}
} else {
if($check[0] == $tomorrow) {
echo "\n\n";
$tom = "tomorrow found in cache $test[$mimi]
\n";
if(in_array("", $check)) { // at least one value missing
echo "\n";
$tom .= "at least one value missing
\n";
if(filemtime("noaarecdat.txt") < $check_it ) $noaagrab = true;
}
$thisDayCacheMax1 = $check[1];
$thisDayCacheMaxYear1 = $check[2];
$thisDayCacheMin1 = $check[3];
$thisDayCacheMinYear1 = $check[4];
$thisDayCacheMaxAvg1 = $check[5];
$thisDayCacheMinAvg1 = $check[6];
} // end tomorrow check
} // end check day
$mimi++;
} // end foreach
} else { // cachefile dosen't exist
echo "\n";
// if($noaabug) echo "NO cachefile
\n";
$noaagrab = true;
} // end if test
if($tod) {
if($noaabug) echo $tod;
} else {
echo "\n";
if($noaabug) echo "NO today found in cache
\n";
$noaagrab = true;
}
if($tom) {
if($noaabug) echo $tom;
} else {
echo "\n";
if($noaabug) echo "NO tomorrow found in cache
\n";
if(filemtime("noaarecdat.txt") < $check_it ) $noaagrab = true;
}
// if required noaagrab ...
// ***********************************************************************
if($noaagrab || $noaabug) {
// OK need to get the data
echo "\n\n";
$bugout .= "
Ring NOAA ....
\n"; # if($all = file_get_contents("https://w2.weather.gov/climate/getclimate.php?pil=CLI&recent=yes&wfo=".$wfo."&sid=".$sid)) { # https://forecast.weather.gov/product.php?site=BIS&issuedby=BIS&product=CLI&format=txt&version=1&glossary=0 $fnameIn = "https://forecast.weather.gov/product.php?site=".strtoupper($wfo)."&issuedby=".strtoupper($sid)."&product=CLI&format=txt&version=1&glossary=0"; echo "\n"; $STRopts = array( 'http'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0)\r\n" ), 'https'=>array( 'method'=>"GET", 'protocol_version' => 1.1, 'header'=>"Cache-Control: no-cache, must-revalidate\r\n" . "Cache-control: max-age=0\r\n" . "Connection: close\r\n" . "User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0)\r\n" ) ); $STRcontext = stream_context_create($STRopts); if($all = file_get_contents($fnameIn,0,$STRcontext)) { echo "\n"; #echo "\n"; #$stage1 = explode("
", $all); #$stage2 = explode("", $stage1[1]); // stage2[0] now has the contents of the tags #$thedata = explode("\n", $stage2[0]); // create an array of 'lines' // If there are problems NOAA returns "Sorry - no records found .. // usually caused by incorrect station id(s) preg_match_all('!
]*>(.*)!Uis',$all,$matches); #print "\n"; if(isset($matches[1][0])) {$thedata = explode("\n",$matches[1][0]); } else {$thedata = array(); } if(strpos($thedata[0], "Sorry")) { $err = true; echo "\n\n"; echo ($noaabug ? " NOAA says NO RECORDS FOUND !!
/n" : ""); } // step through the lines looking for max and min (occurs twice, we may want second event) // ** ALL CHANGE - need to see if it says today or yesterday - is it that simple ? (not quite) ** if($err === false){ $rec_found = 0; $firstblock = false; $maxLine = false; $minLine = false; $mass = false; foreach($thedata as $aline) { $rec_found++; if(strpos($aline, "CLIMATE SUMMARY")) { $cheese = explode(" ", $aline); $recDay = $cheese[(count($cheese) - 2)]; if($noaabug) echo "
recDay: " .$recDay. ", serverDay: " .$serverDay. ", Tomorrow: " .$tomorrow. "
\n";
$bugout .= $aline;
if($recDay == $serverDay) {
$firstblock = true;
echo "\n\n";
$bugout .= "Use first block ....
\n";
} else {
$firstblock = false;
echo "\n\n";
$bugout .= "Use second block ....
\n";
}
$bugout .= $thedata[$rec_found]. "
\n" .$thedata[$rec_found +1]. "
\n" .$thedata[$rec_found +2]. "
\n" .$thedata[$rec_found +3]."
\n" .$thedata[$rec_found +4]. "
\n";
}
// if(strpos($aline, "(F)")) echo "Found @ $rec_found
";
if(strpos($aline, "(F)") && $rec_found <30) $mass = true;
if($mass === true) {
if(strpos($aline, "TODAY") && $rec_found < 25 && $recDay == $serverDay) {
// echo "test line $rec_found
";
$bugout .= $thedata[$rec_found -2]. "
\n" .$thedata[$rec_found -1]. "
\n";
}
if($firstblock === true && $rec_found < 70) {
if( strpos($aline, "MAXIMUM" ) !== false) {
$bugout .= "
".$aline."\n"; $thisDayMax = trim(substr($aline, 31, 3), " M"); // remove white space and possible M[issing] $thisDayMaxYear = trim(substr($aline, 38, 4), " M"); // remove white space and possible M[issing] $thisDayMaxAvg = trim(substr($aline, 43, 3), " M"); // remove white space and possible M[issing] $bugout .= "This Day Record Max. Temp: ".$thisDayMax."°F @ ".$thisDayMaxYear."
".$aline."\n"; $thisDayMin = trim(substr($aline, 31, 3), " M"); // remove white space and possible M[issing] $thisDayMinYear = trim(substr($aline, 38, 4), " M"); // remove white space and possible M[issing] $thisDayMinAvg = trim(substr($aline, 43, 3), " M"); // remove white space and possible M[issing] $bugout .= "This Day Record Min. Temp: ".$thisDayMin."°F @ ".$thisDayMinYear."
\n";
$bugout .= $thedata[$rec_found -1]. "
\n";
} else {
$bugout2 = "\n
Checking second block ...
\n";
$bugout2 .= $thedata[$rec_found -1]. "
\n";
}
}
if( strpos($aline, "MAXIMUM TEMPERATURE" ) !== false) {
if($firstblock !== false) {
$bugout2 .= "
* ".$aline."\n"; $thisDayMax1 = trim(substr($aline, 36, 3), " RM"); // remove white space and possible R[ecord] / M[issing] $thisDayMaxYear1 = trim(substr($aline, 45, 4), " M"); $thisDayMaxAvg1 = trim(substr($aline,26,3), " M"); $bugout2 .= "Record Max. Temp: ".$thisDayMax1."°F @ ".$thisDayMaxYear1."
* ".$aline."\n"; $thisDayMax = trim(substr($aline, 36, 3), " RM"); // remove white space and possible R[ecord] / M[issing] $thisDayMaxYear = trim(substr($aline, 45, 4), " M"); $thisDayMaxAvg = trim(substr($aline,26,3), " M"); $bugout .= "Record Max. Temp: ".$thisDayMax."°F @ ".$thisDayMaxYear."
* ".$aline."\n"; $thisDayMin1 = trim(substr($aline, 36, 3), " RM"); // remove white space and possible R[ecord] / M[issing] $thisDayMinYear1 = trim(substr($aline, 45, 4), " M"); $thisDayMinAvg1 = trim(substr($aline,26,3), " M"); $bugout2 .= "This Day Record Min. Temp: ".$thisDayMin1."°F @ ".$thisDayMinYear1."
* ".$aline."\n"; $thisDayMin = trim(substr($aline, 36, 3), " RM"); // remove white space and possible R[ecord] / M[issing] $thisDayMinYear = trim(substr($aline, 45, 4), " M"); $thisDayMinAvg = trim(substr($aline,26,3), " M"); $bugout .= "This Day Record Min. Temp: ".$thisDayMin."°F @ ".$thisDayMinYear."
NEW cache out: ".$recout."
"; echo "\n"; } // END MAIN PROG if($noaabug) {?>
This Day | |
°F |
°F |
Optional | |
°F |
°F |