USA EXTREME'S SCRIPT not working

hello All…

The USA Extreme’s script on everyone’s left side bar is showing N/A…anyone know the fix or the problem?

Inside the script is this address but when I go there it says this feature has reached it’s end…

http://www.wunderground.com/climate/extremes.asp

Thanks…Chris

Wunderground pulled the plug on the extremes.

Yep, and there appears to be no equivalent in the WU API. So… time to retire that script. I’m not aware of any other source for that data (that we could use).

Correction, I found a NWS site that has the data for high/low temperatures in the USA (but doesn’t have the precip data, so $usaprecip will always return ‘N/A’).

Try this for usaextremes.php

<?php
############################################################################
#
#   Project:    USA Extremes
#   Module:     usaextremes.php
#   Purpose:    Provides USA Extremes for Web page display
#   Authors:    Michael ([email protected])
#               Ken True ([email protected]) V2.01, V2.02
############################################################################
#      Usage:  Place the following on your webpage
#      CHMOD 666 for cacheFile2.php
#      include_once('usaextremes.php');
#      
#      Then call the following tags within the page where you would like them displayed:
#      $usahigh
#      $usalow
#      $usaprecip (note: $usaprecip will be 'N/A' in V2.02
#
#  Note: allow_url_fopen = on 
#    in your php.ini is required to run this script.
############################################################################
// version
// Version 2.00 - 14-Sep-2010 - initial release
// Version 2.01 - 21-Sep-2012 - adapted for WeatherUnderground use - K. True
// Version 2.02 - 23-Aug-2016 - adapted for www.wpc.ncep.noaa.gov - K. True
$usaextremesverion = "2.02";
echo "<!-- USA Extremes Script Version $usaextremesverion. -->\n";
/////////////////////////////////////////////////////////////////////////////
//SETTINGS START HERE////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Site to Parse
$url2 = "http://www.wpc.ncep.noaa.gov/discussions/hpcdiscussions.php?disc=nathilo";
// Set the time zone
$ourTZ = 'America/New_York';
// Name of cache file  --  This file must be set to CHMOD-666
$cacheFile2 = "usaextremesCache3.txt";  
// Age of cache file before re-fetch caching time, in seconds (3600 = 1 hour)
$cache_life = '3600'; 
/////////////////////////////////////////////////////////////////////////////
//END SETTINGS///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// 
if (file_exists($cacheFile2)) {
    $filemtime = filemtime($cacheFile2);
    $filesize = filesize($cacheFile2);
    if (0 == $filesize){
        $filemtime = 0;
    }
} else {
    $filemtime = 0;
}   
//   open the cache file and write the new data and then close the file.
$forceRefresh = (isset($_REQUEST['force']))?true:false;
$current_time = time();
$cache_age = $current_time - $filemtime;
if ($forceRefresh or $cache_age >= $cache_life){
   print "<!-- fetching from '$url2' -->\n";
   $html2 = curl_get_contents($url2); 
   $fp2 = fopen($cacheFile2, 'w');
   fwrite($fp2, $html2);
   fclose($fp2);
   echo "<!-- The cache life HAS expired and fresh data re-wrote the cache file -->\n";
} else {
   echo "<!-- The cache life HAS NOT expired and fresh data was not written to the cache file -->\n";
// Open the cache file, read it, then close it   
    $handle2 = fopen($cacheFile2, "r");
    $filesize = filesize($cacheFile2);
    $html2 = fread($handle2, $filesize);
    fclose($handle2);
}

function curl_get_contents($url){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
		$data = curl_exec($ch);
		curl_close($ch);
		return $data;
}

/* looking for:

<hr width="100%"> 
  <div id="printarea">
<pre><font face="arial,helvetica">National High and Low Temperature (for the contiguous United States)
NWS Weather Prediction Center, College Park, MD
Issued 8 pm EDT Tuesday, August 23, 2016

High Temperature for Tuesday, August 23, 2016
<span style="font-size:.9em;">(as received by 8 pm EDT August 23)</span>
<b>107 at Imperial, CA</b>

Low Temperature for Tuesday, August 23, 2016
<span style="font-size:.9em;">(as received by 8 pm EDT August 23)</span>
<b>19 at Stanley, ID</b>
</font></pre>
  </div>
</div>

or

<hr width="100%"> 
  <div id="printarea">
<pre><font face="arial,helvetica">National High and Low Temperature (for the contiguous United States)
NWS Weather Prediction Center, College Park, MD
Issued 2 am EDT Tuesday, August 23, 2016

High Temperature for Monday, August 22, 2016
<span style="font-size:.9em;">(as received by 2 am EDT August 23)</span>
<b>113 at Death Valley, CA</b>

Low Temperature for Monday, August 22, 2016
<span style="font-size:.9em;">(as received by 2 am EDT August 23)</span>
<b>27 at Bondurant, WY</b>
<b>27 at Stanley, ID</b>
<b>27 at Yellowstone National Park South Entrance, WY</b>
</font></pre>
  </div>
</div>

*/

//Finds USA High
preg_match_all('|High Temperature for .*</span>(.*)Low Temperature|Uis', $html2, $matches);
//  print "<pre>\n".print_r($matches,true)."</pre>\n";

if(isset($matches[1][0])) { 
//  print "<!-- high matches \n".print_r($matches,true)."-->\n";

  $usahigh = trim($matches[1][0]);
  $usahigh = str_replace('</b>','</b>
',$usahigh);
  $usahigh = strip_tags($usahigh,'
');  
  print "<!-- usahigh='$usahigh' -->\n";
} else {
   $usahigh = 'N/A';
}

//Finds USA Low
preg_match_all('|Low Temperature for .*</span>(.*)</font>|Uis', $html2, $matches);
//  print "<!-- low matches \n".print_r($matches,true)."-->\n";

if(isset($matches[1][0])) { 
  
  $usalow = trim($matches[1][0]);
  $usalow = str_replace('</b>','</b>
',$usalow);
  $usalow = strip_tags($usalow,'
');
    
  //echo $usalow;
  print "<!-- usalow='$usalow'-->\n";
} else {
   $usalow = 'N/A';
}

/* -- note: precip not included in www.wpc.ncep.noaa.gov data - K. True

//Finds USA High Precip
preg_match_all('|<div id="precip"[^>]*>(.*)</div>|Uis', $html2, $matches);
//  print "<pre>\n".print_r($matches,true)."</pre>\n";

if(isset($matches[1][0])) { 
  $raintable = $matches[1][0]; 
  preg_match_all('|<td>(.*)</td>|Uis',$raintable,$matches);
  
//  print "<pre>\n".print_r($matches,true)."</pre>\n";

  $usaprecip = trim(preg_replace("|\n|is",'',strip_tags($matches[1][2]).'
'.strip_tags($matches[1][0])));  
  print "<!-- usaprecip='$usaprecip' -->\n";
} else {
   $usaprecip = 'N/A';
}
*/
$usaprecip = 'N/A';
print "<!-- usaprecip='$usaprecip' -->\n";
print '<!-- $filemtime = '.$filemtime.' $cache_age = '.$cache_age.' seconds.' . " -->\n";
print "<!-- Cache refresh rate = $cache_life seconds.  Cache age = $cache_age seconds. -->\n";
?>

Awesome… Thanks Ken.

Since I seem to have been the one to update this script, I’ve decided to adopt it (awwww…) and give it a home in my script page for NWS miscellaneous scripts. The code has been updated to add a self-downloader and a little comment cleanup, I’ve started numbering this version at 4.00 (so as not to confuse it with Michael’s V3.x version which he his not distributing). This version uses the NWS CPC site and now includes $usaprecip and $reportDate entries in addition to the $usahigh and $usalow values.

Best regards,
Ken

Ken - Thank s a bunch! :smiley:

Thanks Ken for taking over this script.

Thanks Ken

BTrip


Screen Shot 2016-09-13 at 9.10.13 PM.png

Have a small update to the script V4.01 14-Sep-2016 to correct an issue with a malformed data record. Please replace your usaextremes.php script with the update.