Author Topic: Forecast Summary issue.  (Read 3416 times)

0 Members and 1 Guest are viewing this topic.

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Forecast Summary issue.
« on: November 02, 2017, 08:23:03 PM »
I haven't messed with any coding and all of a sudden i get this..

Notice: Undefined offset: 1 in /home/mkutche/public_html/forecast-summary.php on line 130

Notice: Undefined offset: 1 in /home/mkutche/public_html/forecast-summary.php on line 132

Thanks
Mike
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #1 on: November 02, 2017, 08:34:19 PM »
Can you post the snippet of code getting the errors?
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #2 on: November 02, 2017, 08:35:33 PM »
Can you post the snippet of code getting the errors?

Not sure which ones are getting errors.
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #3 on: November 02, 2017, 08:36:49 PM »
thats lines 130 and 132.
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #4 on: November 02, 2017, 08:48:26 PM »
In the meantime I took a look by myself using Ken's sce=view tool.

Before digging further, you may want to update the file as you are two versions behind (1.03 vs. 1.05).  You can cut-and-paste the current version here:

  http://saratoga-weather.org/forecast-discussion.php?sce=view

Actually, I saw it work once.  It looks like when it fails, it is trying to read the cache file.  If you delete the cache file, does it work the next time?
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #5 on: November 02, 2017, 08:51:18 PM »
just says forecast unavailable. It does have something in the forecast-summary.txt file
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #6 on: November 02, 2017, 09:03:29 PM »
OK, I tried this:

  http://www.gosportwx.com/forecast-summary.php?cache

which is supposed to force the cache to reload.  In the source generated I see the following:

Code: [Select]
<!-- forecast-discussion.php V1.03 10-Jan-2008 -->
<!-- loading forecast-summary.txt from http://forecast.weather.gov/product.php?site=NWS&issuedby=IND&product=AFD&format=txt&version=1&glossary=0&highlight=off -->
<!-- Network error: Connection timed out (110) -->
<!-- cache written to forecast-summary.txt. -->
<pre>

In other words, the forecast discussion fetch is failing, and that result gets written to the cache.

So just before the code that fails under "extract the forecast discussion" there needs to be a check to see that there actually is one.  So just after the preg_match() call, you could insert:

Code: [Select]
discussion = '';
if (isset($matches[1]) {

and then add
Code: [Select]
}
right after

Code: [Select]
// uncomment next line if you like only lower case text, or it could be made an option
//  $discussion  = strtolower(trim($matches[1]));

That way you'll skip the code that is causing the problem when you don't have a valid discussion.  Eventually the fetch will (should) be successful and you'll get the discussion again.

Check this carefully.  I may have messed up something as I'm watching hockey as I write this.  :grin:



https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #7 on: November 02, 2017, 09:18:05 PM »
didn't seem to work idk why it cannot connect its updated on NWS website..
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #8 on: November 02, 2017, 09:41:20 PM »
I missed a parentheses:

Code: [Select]
if (isset($matches[1]) ) {
Not sure why it is timing out. In any case, I'm guessing Ken has a rewrite of this in the works to use the new NWS API (which doesn't require the HTML scraping).

https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #9 on: November 02, 2017, 09:42:42 PM »
something is up because i just updated SE Lincoln's NOAA Text Products and his are working but mine arent..

http://gosportwx.com/wxnoaaproducts.php

https://gwwilkins.org/wxnoaaproducts.php

also cnyweather.com uses the Forecast Summary too no issues on his end..
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #10 on: November 02, 2017, 09:51:45 PM »
There may be something weird going on with your server. I was able to get a good fetch but here's what happened:

Code: [Select]
<!-- forecast-summary.php V1.00 10-Jan-2016 -->
<!-- loading forecast-summary.txt from http://forecast.weather.gov/product.php?site=NWS&issuedby=IND&product=AFD&format=txt&version=1&glossary=0&highlight=off -->
<!-- unable to save cache to forecast-summary.txt. -->

If I look at http://www.gosportwx.com/forecast-summary.txt I see:

Code: [Select]
.SYNOPSIS...
Conditions will be primarily dry and warm tonight. A cold front
will then cross the region Friday with a few showers, followed
by cooler air. The best chance of rain will be in central New
York. Saturday will be dry and seasonable. Rain showers will
return Saturday night.

Can you go on the server and check the permissions and last write date/time on forecast-summary.txt, then delete it?
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #11 on: November 02, 2017, 09:54:34 PM »
from gosportwx.com/forecast-summary.txt now i get

Quote
HTTP/1.0 301 Moved Permanently
Server: Apache
Location: http://forecast.weather.gov/product.php?site=NWS&issuedby=IND&product=AFD&format=CI&version=1&glossary=0
Content-Length: 332
Content-Type: text/html; charset=iso-8859-1
Date: Fri, 03 Nov 2017 01:59:22 GMT
Connection: close

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://forecast.weather.gov/product.php?site=NWS&amp;issuedby=IND&amp;product=AFD&amp;format=CI&amp;version=1&amp;glossary=0">here</a>.</p>
</body></html>

but i still get this ...

Notice: Undefined offset: 1 in /home/mkutche/public_html/forecast-summary.php on line 130

Notice: Undefined offset: 1 in /home/mkutche/public_html/forecast-summary.php on line 132
« Last Edit: November 02, 2017, 10:02:41 PM by mkutche »
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #12 on: November 02, 2017, 10:04:03 PM »
It looks to be really flaky as to whether a good fetch happens or not. And if you don't get a good fetch, you are stuck with the bad cache file for a half hour.

What you could do (this is starting to get a bit hairy - if you do this, save a version of the file as it is now) is move the cache writing code so that it only executes if the fetch was good.  That is this code:

Code: [Select]
      $fp = fopen($cacheName, "w");
  if ($fp) {
        $write = fputs($fp, $html);
         fclose($fp); 
         print "<!-- cache written to $cacheName. -->\n";
  } else {
     print "<!-- unable to save cache to $cacheName. -->\n";
  }

You'd move that after the new "if":

Code: [Select]
if (isset($matches[1]) ) {
And then delete the forecast-summary.txt file again. The goal here is to only cache a result if you get one and to force a new fetch each time until you get a good one.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #13 on: November 02, 2017, 10:40:31 PM »
Hi again,

I just tried it with Ken's newer code (forecast-discussion.php 1.05) and it looks like it works consistently - takes care of the issue you are seeing.

So I'd try swapping that in (with your mods for location) and ignoring the other changes I put above for now (although the code *should* deal with a flaky server eventually).
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #14 on: November 02, 2017, 10:45:33 PM »
Hi again,

I just tried it with Ken's newer code (forecast-discussion.php 1.05) and it looks like it works consistently - takes care of the issue you are seeing.

So I'd try swapping that in (with your mods for location) and ignoring the other changes I put above for now (although the code *should* deal with a flaky server eventually).

I updated the script and still getting the same thing.
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #15 on: November 03, 2017, 10:24:33 AM »
I still see the 1.03 code when I do a sce=view. Did you put that back?

After installing the new code, you either need to delete the cache file or wait for it to time out for the new code to take effect.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #16 on: November 03, 2017, 02:09:27 PM »
I still see the 1.03 code when I do a sce=view. Did you put that back?

After installing the new code, you either need to delete the cache file or wait for it to time out for the new code to take effect.

shouldnt need to update forecast-summary.php because it works fine on CNYweather.com
« Last Edit: November 03, 2017, 02:11:27 PM by mkutche »
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2295
    • CNYWeather
Re: Forecast Summary issue.
« Reply #17 on: November 03, 2017, 02:50:51 PM »
I still see the 1.03 code when I do a sce=view. Did you put that back?

After installing the new code, you either need to delete the cache file or wait for it to time out for the new code to take effect.

shouldnt need to update forecast-summary.php because it works fine on CNYweather.com

My version is 1.05

Here's the code and you'll only have to change line 61 the $filename. I did notice also, it doesnt work with putting https in the link to the text discussion

Code: [Select]
<?php
// PHP script by Ken True, webmaster@saratoga-weather.org
// forecast-discussion.php  version 1.00 - 14-Dec-2007
//   Version 1.01 - 14-Dec-2007 - added safety features per MChallis at http://www.carmosaic.com/weather/
//   Version 1.02 - 31-Dec-2007 - changed fetchUrlWithoutHanging function to fetchUrlWithoutHangingFD
//   Version 1.03 - 10-Jan-2008 - added "Forecast Discussion unavailable" feature per MChallis
//   Version 1.04 - 31-Jul-2012 - changes to support NWS website redesign
//   Version 1.05 - 31-Mar-2015 - fixed for change to NWS website access
// 
    
$Version "forecast-discussion.php V1.05 31-Mar-2015";
//  error_reporting(E_ALL);  // uncomment to turn on full error reporting
// script available at http://saratoga-weather.org/scripts.php
//  
// you may copy/modify/use this script as you see fit,
// no warranty is expressed or implied.
//
// Customized for: NOAA forecast discussions
//   http://www.crh.noaa.gov/product.php?site=NWS&issuedby=MTR&product=AFD&format=CI&version=1&glossary=0
//
// To find your local NWS office code for $myNWS, do this:
//   go to www.weather.gov
//   search for your city, state
//   look at the URL in the 'Forecast Discussion' link near the bottom of the page
//   use the 3-character abbreviation is in the &issuedby=XXX parameter on the 
//     Forecast Discussion link (XXX will be your local office)
//   put the XXX in the $myNWS variable below
//
// output: creates XHTML 1.0-Strict HTML page (default)
// Options on URL:
//      inc=Y    -- returns only the body code for inclusion
//                         in other webpages.  Omit to return full HTML.
// example URL:
//  http://your.website/forecast-discussion.php?inc=Y
//  would return data without HTML header/footer 
//
// Usage:
//  you can use this webpage standalone (customize the HTML portion below)
//  or you can include it in an existing page:
//  no parms:  $doIncludeFD = true; include("forecast-discussion.php"); 
//  parms:    include("http://your.website/forecast-discussion.php?inc=Y");
//
//
// settings:  
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
// 
  
$myNWS 'BGM';   // San Francisco, NWS office
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
//
  
$cacheName "forecast-discussion.txt";  // used to store the file so we don't have to
//                          fetch it each time
  
$refetchSeconds 1800;     // refetch every nnnn seconds

  
$cacheFileDir './';      // default cache file directory

// end of settings

// Constants
// don't change $fileName or script may break ;-)
  
$fileName "http://forecast.weather.gov/product.php?site=NWS&issuedby=BGM&product=AFD&format=CI&version=1&glossary=0";
// end of constants

// ------ start of code -------
if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
   
$filenameReal __FILE__;
   
$download_size filesize($filenameReal);
   
header('Pragma: public');
   
header('Cache-Control: private');
   
header('Cache-Control: no-cache, must-revalidate');
   
header("Content-type: text/plain");
   
header("Accept-Ranges: bytes");
   
header("Content-Length: $download_size");
   
header('Connection: close');
   
readfile($filenameReal);
   exit;
}

global 
$SITE;
if (isset(
$SITE['cacheFileDir']))   {$cacheFileDir $SITE['cacheFileDir']; }

// Check parameters and force defaults/ranges
if ( ! isset($_REQUEST['inc']) ) {
        
$_REQUEST['inc']="";
}
if (isset(
$doIncludeFD) and $doIncludeFD ) {
  
$includeMode "Y";
 } else {
  
$includeMode $_REQUEST['inc']; // any nonblank is ok
}

if (
$includeMode) {$includeMode "Y";}

if (isset(
$_REQUEST['cache'])) {$refetchSeconds 1; }

// omit HTML <HEAD>...</HEAD><BODY> if only tables wanted
// --------------- customize HTML if you like -----------------------
if (! $includeMode) {
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Refresh" content="300" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Forecast Discussion for <?php print $myNWS ?> NWS Office</title>
</head>
<body style="background-color:#FFFFFF;">
<?php
}

// ------------- code starts here -------------------
echo "<!-- $Version -->\n";

$cacheName $cacheFileDir $cacheName

// refresh cached copy of page if needed
// fetch/cache code by Tom at carterlake.org

if (file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds time()) {
      print 
"<!-- using Cached version of $cacheName -->\n";
      
$html implode(''file($cacheName));
    } else {
      print 
"<!-- loading $cacheName from $fileName -->\n";
      
$html fetchUrlWithoutHangingFD($fileName);
      
$fp fopen($cacheName"w");
  if ($fp) {
        
$write fputs($fp$html);
         
fclose($fp);  
         print 
"<!-- cache written to $cacheName. -->\n";
  } else {
     print "<!-- unable to save cache to $cacheName. -->\n";
  }
}
  
// extract the forecast discussion
 
preg_match('|<pre[^>]*>(.*)</pre>|Usi',$html,$matches);
 
$discussion $matches[1]; // now have the forecast as a string with \n delimiters

$discussion  trim($matches[1]); // prevent extra white space at beginning and end

 // uncomment next line if you like only lower case text, or it could be made an option
 // $discussion  = strtolower(trim($matches[1]));

  
if ($discussion  == '') {
           
$discussion  'Forecast discussion unavailable, please try later.';
  }
  print 
"<pre>\n";
  print 
htmlspecialchars(strip_tags($discussion));
  print 
"</pre>\n";  $niceFileName preg_replace('!&!is','&amp;',$fileName);
  print 
"<p><small><a href=\"$niceFileName\">NWS $myNWS Office Area Forecast Discussion</a></small></p>\n";
// print footer of page if needed    
// --------------- customize HTML if you like -----------------------
if (! $includeMode ) {   
?>


</body>
</html>

<?php
}

// ----------------------------functions ----------------------------------- 
 
 
function fetchUrlWithoutHangingFD($url// thanks to Tom at Carterlake.org for this script fragment
   
{
   
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   
$numberOfSeconds=4;   

   
// Suppress error reporting so Web site visitors are unaware if the feed fails
   
error_reporting(0);

   
// Extract resource path and domain from URL ready for fsockopen

   
$url str_replace("http://","",$url);
   
$urlComponents explode("/",$url);
   
$domain $urlComponents[0];
   
$resourcePath str_replace($domain,"",$url);

   
// Establish a connection
   
$socketConnection fsockopen($domain80$errno$errstr$numberOfSeconds);

   if (!
$socketConnection)
       {
       
// You may wish to remove the following debugging line on a live Web site
          
print "<!-- Network error: $errstr ($errno) -->\n";
       }    
// end if
   
else    {
       
$xml '';
        
fputs($socketConnection"GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nCache-Control: no-cache, must-revalidate\r\nCache-control: max-age=0\r\nConnection: close\r\nUser-agent: Forecast loader\r\nAccept: text/plain,text/html\r\n\r\n");
  
       
// Loop until end of file
       
while (!feof($socketConnection))
           {
           
$xml .= fgets($socketConnection4096);
           }    
// end while

       
fclose ($socketConnection);

       }    
// end else

   
return($xml);

   }    
// end function
   
// --------------end of functions ---------------------------------------

?>
Tony




Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #18 on: November 03, 2017, 03:07:27 PM »
Tony, that's your forecast-DISCUSSION.php file, vs. the forecast-SUMMARY.php file (all kind of confusing because the two files are similar).

Here are the differences between the code on the two sites:

Code: [Select]
$ diff gosport.php cny.php
8c8
< $Version = "forecast-discussion.php V1.03 10-Jan-2008";
---
> $Version = "forecast-summary.php V1.00 10-Jan-2016";
46c46
< $myNWS = 'IND';   // Tucson, AZ
---
> $myNWS = 'BGM';   // Tucson, AZ
57c57
< $fileName = "http://forecast.weather.gov/product.php?site=NWS&issuedby=IND&product=AFD&format=CI&version=1&glossary=0";
---
> $fileName = "http://forecast.weather.gov/product.php?site=NWS&issuedby=BGM&product=AFD&format=txt&version=1&glossary=0&highlight=off";
133c133,134
< $sstring = '...'; // start of synopis quick text
---
> $discussion = str_replace(array("\r", "\n"), ' ', $discussion); //delete the linefeeds in the middle
> $sstring = 'SYNOPSIS'; // start of synopis quick text
137,138c138,140
< $discuss = substr($discussion, $start+3, ($end-4-$start)); // new text (too long to print in cell format)
< $discussion = wordwrap ($discuss, 45); // for cell phone 45 characters.
---
> $discuss = substr($discussion, $start+0, ($end-1-$start)); // new text (too long to print in cell format)
> $charwrap = round($pagewidth/7.25);
> $discussion = wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.
141c143
< // $discussion  = strtolower(trim($matches[1]));
---
> //  $discussion  = strtolower(trim($matches[1]));
188,189c190
<     fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
<     
---
>     fputs($socketConnection, "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nCache-Control: no-cache, must-revalidate\r\nCache-control: max-age=0\r\nConnection: close\r\nUser-agent: Forecast loader script\r\nAccept: text/plain,text/html\r\n\r\n");


If I take the CNY code and swap out IND for BGM in the two places it occurs, it works for me.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2295
    • CNYWeather
Re: Forecast Summary issue.
« Reply #19 on: November 03, 2017, 03:18:59 PM »
I'm sorry about that. Yeah, they are pretty much the same file, just looking for different text files on the NWS server.

forecast vs. discussion.

Sorry about the confusion  :sad:
Tony




Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #20 on: November 03, 2017, 04:07:29 PM »
ok so now how do i get it to just say:

.SYNOPSIS...
Issued at 328 PM EDT Fri Nov 3 2017

High pressure over the great lakes will move on to the east and a
warm front across Tennessee and Arkansas will move north across
Indiana Saturday.

Low pressure moving from Iowa into the great lakes will pull a cold
front south across Indiana late Sunday and Sunday night. Severe
storms are possible Late Sunday and Sunday night as the air mass
ahead of the cold front will be quite unstable.

The cold front will temporarily stall across southern Kentucky and
Tennessee and a couple areas of low pressure may bring a chance of
rain showers late Monday and Tuesday.  Otherwise...cool and dry
weather will occur from the middle of next week on as high pressure
builds in from the northwest.
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2295
    • CNYWeather
Re: Forecast Summary issue.
« Reply #21 on: November 03, 2017, 04:37:06 PM »
I'm trying to remember. It gets trimmed in this part of the code I believe.

Code: [Select]
$discussion  = trim($matches[1]); // prevent extra white space at beginning and end
$discussion = str_replace(array("\r", "\n"), ' ', $discussion); //delete the linefeeds in the middle
$sstring = 'SYNOPSIS'; // start of synopis quick text
$estring = '&&'; // first divider
$start = strpos($discussion,$sstring); // starting position of where to keep
$end = strpos($discussion,$estring); // end of where to keep
$discuss = substr($discussion, $start+0, ($end-1-$start)); // new text (too long to print in cell format)
$charwrap = round($pagewidth/7.25);
$discussion = wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.

Maybe one of the wizards can explain it. It should start at the word synopsis and chop it at the && I think.

I dont see that in your ?sce=view of the code.
« Last Edit: November 03, 2017, 04:39:33 PM by CNYWeather »
Tony




Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #22 on: November 03, 2017, 04:38:05 PM »
I'm trying to remember. It gets trimmed in this part of the code I believe.

Code: [Select]
$discussion  = trim($matches[1]); // prevent extra white space at beginning and end
$discussion = str_replace(array("\r", "\n"), ' ', $discussion); //delete the linefeeds in the middle
$sstring = 'SYNOPSIS'; // start of synopis quick text
$estring = '&&'; // first divider
$start = strpos($discussion,$sstring); // starting position of where to keep
$end = strpos($discussion,$estring); // end of where to keep
$discuss = substr($discussion, $start+0, ($end-1-$start)); // new text (too long to print in cell format)
$charwrap = round($pagewidth/7.25);
$discussion = wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.

Maybe one of the wizards can explain it. It should start at the word synopsis and chop it at the && I think.

ok thanks man i'll see what i can do :)
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 946
    • LexMAWeather
Re: Forecast Summary issue.
« Reply #23 on: November 03, 2017, 05:35:13 PM »
It looks like you have the forecast-discussion.php file contents now in forecast-summary.php.

It might be that the only difference between the discussion and summary code is the code snippet above. I'd recommend just taking the code from the CNY site, replacing your forecast-summary.php with that code, plugging in "IND" for "BGM", and trying that.

The CNY code is here:

Code: [Select]
<?php
// PHP script by Ken True, webmaster@saratoga-weather.org
// forecast-discussion.php  version 1.00 - 14-Dec-2007
//   Version 1.01 - 14-Dec-2007 - added safety features per MChallis at http://www.carmosaic.com/weather/
//   Version 1.02 - 31-Dec-2007 - changed fetchUrlWithoutHanging function to fetchUrlWithoutHangingFD
//   Version 1.03 - 10-Jan-2008 - added "Forecast Discussion unavailable" feature per MChallis
//
    
$Version "forecast-summary.php V1.00 10-Jan-2016";
//  error_reporting(E_ALL);  // uncomment to turn on full error reporting
// script available at http://saratoga-weather.org/scripts.php
//  
// you may copy/modify/use this script as you see fit,
// no warranty is expressed or implied.
//
// Customized for: NOAA forecast discussions
//   http://www.crh.noaa.gov/product.php?site=NWS&issuedby=MTR&product=AFD&format=CI&version=1&glossary=0
//
// To find your local NWS office code for $myNWS, do this:
//   go to www.weather.gov
//   search for your city, state
//   look at the URL in the 'Forecast Discussion' link near the bottom of the page
//   use the 3-character abbreviation is in the &issuedby=XXX parameter on the 
//     Forecast Discussion link (XXX will be your local office)
//   put the XXX in the $myNWS variable below
//
// output: creates XHTML 1.0-Strict HTML page (default)
// Options on URL:
//      inc=Y    -- returns only the body code for inclusion
//                         in other webpages.  Omit to return full HTML.
// example URL:
//  http://your.website/forecast-discussion.php?inc=Y
//  would return data without HTML header/footer 
//
// Usage:
//  you can use this webpage standalone (customize the HTML portion below)
//  or you can include it in an existing page:
//  no parms:  $doIncludeFD = true; include("forecast-discussion.php"); 
//  parms:    include("http://your.website/forecast-discussion.php?inc=Y");
//  parms:    include("http://your.website/forecast-discussion.php?inc=Y");
//
//
// settings:  
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
// 
  
$myNWS 'BGM';   // Tucson, AZ
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
//
  
$cacheName "forecast-summary.txt";  // used to store the file so we don't have to
//                          fetch it each time
  
$refetchSeconds 1;     // refetch every nnnn seconds
// end of settings

// Constants
// don't change $fileName or script may break ;-)
  
$fileName "http://forecast.weather.gov/product.php?site=NWS&issuedby=BGM&product=AFD&format=txt&version=1&glossary=0&highlight=off";
// end of constants

// ------ start of code -------
if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
   
$filenameReal __FILE__;
   
$download_size filesize($filenameReal);
   
header('Pragma: public');
   
header('Cache-Control: private');
   
header('Cache-Control: no-cache, must-revalidate');
   
header("Content-type: text/plain");
   
header("Accept-Ranges: bytes");
   
header("Content-Length: $download_size");
   
header('Connection: close');
   
readfile($filenameReal);
   exit;
}

// Check parameters and force defaults/ranges
if ( ! isset($_REQUEST['inc']) ) {
        
$_REQUEST['inc']="";
}
if (isset(
$doIncludeFD) and $doIncludeFD ) {
  
$includeMode "Y";
 } else {
  
$includeMode $_REQUEST['inc']; // any nonblank is ok
}

if (
$includeMode) {$includeMode "Y";}

if (isset(
$_REQUEST['cache'])) {$refetchSeconds 1; }

// omit HTML <HEAD>...</HEAD><BODY> if only tables wanted
// --------------- customize HTML if you like -----------------------
if (! $includeMode) {
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Refresh" content="300" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Forecast Discussion for <?php print $myNWS ?> NWS Office</title>
</head>
<body style="background-color:#FFFFFF;">
<?php
}

// ------------- code starts here -------------------
echo "<!-- $Version -->\n";

// refresh cached copy of page if needed
// fetch/cache code by Tom at carterlake.org

if (file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds time()) {
      print 
"<!-- using Cached version of $cacheName -->\n";
      
$html implode(''file($cacheName));
    } else {
      print 
"<!-- loading $cacheName from $fileName -->\n";
      
$html fetchUrlWithoutHangingFD($fileName);
      
$fp fopen($cacheName"w");
  if ($fp) {
        
$write fputs($fp$html);
         
fclose($fp);  
         print 
"<!-- cache written to $cacheName. -->\n";
  } else {
     print "<!-- unable to save cache to $cacheName. -->\n";
  }
}
  
// extract the forecast discussion
 
preg_match('|<pre[^>]*>(.*)</pre>|Usi',$html,$matches);
 
$discussion $matches[1]; // now have the forecast as a string with \n delimiters

$discussion  trim($matches[1]); // prevent extra white space at beginning and end
$discussion str_replace(array("\r""\n"), ' '$discussion); //delete the linefeeds in the middle
$sstring 'SYNOPSIS'// start of synopis quick text
$estring '&&'// first divider
$start strpos($discussion,$sstring); // starting position of where to keep
$end strpos($discussion,$estring); // end of where to keep
$discuss substr($discussion$start+0, ($end-1-$start)); // new text (too long to print in cell format)
$charwrap round($pagewidth/7.25);
$discussion wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.

 // uncomment next line if you like only lower case text, or it could be made an option
//  $discussion  = strtolower(trim($matches[1]));

 
  
if ($discussion  == '') {
           
$discussion  'Forecast discussion unavailable, please try later.';
  }
  print 
"<pre>\n";
  print 
htmlspecialchars(strip_tags($discussion));
  print 
"</pre>\n";  
// print footer of page if needed    
// --------------- customize HTML if you like -----------------------
if (! $includeMode ) {   
?>


</body>
</html>

<?php
}

// ----------------------------functions ----------------------------------- 
 
 
function fetchUrlWithoutHangingFD($url// thanks to Tom at Carterlake.org for this script fragment
   
{
   
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   
$numberOfSeconds=4;   

   
// Suppress error reporting so Web site visitors are unaware if the feed fails
   
error_reporting(0);

   
// Extract resource path and domain from URL ready for fsockopen

   
$url str_replace("http://","",$url);
   
$urlComponents explode("/",$url);
   
$domain $urlComponents[0];
   
$resourcePath str_replace($domain,"",$url);

   
// Establish a connection
   
$socketConnection fsockopen($domain80$errno$errstr$numberOfSeconds);

   if (!
$socketConnection)
       {
       
// You may wish to remove the following debugging line on a live Web site
          
print "<!-- Network error: $errstr ($errno) -->\n";
       }    
// end if
   
else    {
       
$xml '';
       
fputs($socketConnection"GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nCache-Control: no-cache, must-revalidate\r\nCache-control: max-age=0\r\nConnection: close\r\nUser-agent: Forecast loader script\r\nAccept: text/plain,text/html\r\n\r\n");
       
// Loop until end of file
       
while (!feof($socketConnection))
           {
           
$xml .= fgets($socketConnection4096);
           }    
// end while

       
fclose ($socketConnection);

       }    
// end else

   
return($xml);

   }    
// end function
   
// --------------end of functions ---------------------------------------

?>
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline mkutche

  • Forecaster
  • *****
  • Posts: 1041
    • GosportWx.com
Re: Forecast Summary issue.
« Reply #24 on: November 03, 2017, 05:43:57 PM »
It looks like you have the forecast-discussion.php file contents now in forecast-summary.php.

It might be that the only difference between the discussion and summary code is the code snippet above. I'd recommend just taking the code from the CNY site, replacing your forecast-summary.php with that code, plugging in "IND" for "BGM", and trying that.

The CNY code is here:

Code: [Select]
<?php
// PHP script by Ken True, webmaster@saratoga-weather.org
// forecast-discussion.php  version 1.00 - 14-Dec-2007
//   Version 1.01 - 14-Dec-2007 - added safety features per MChallis at http://www.carmosaic.com/weather/
//   Version 1.02 - 31-Dec-2007 - changed fetchUrlWithoutHanging function to fetchUrlWithoutHangingFD
//   Version 1.03 - 10-Jan-2008 - added "Forecast Discussion unavailable" feature per MChallis
//
    
$Version "forecast-summary.php V1.00 10-Jan-2016";
//  error_reporting(E_ALL);  // uncomment to turn on full error reporting
// script available at http://saratoga-weather.org/scripts.php
//  
// you may copy/modify/use this script as you see fit,
// no warranty is expressed or implied.
//
// Customized for: NOAA forecast discussions
//   http://www.crh.noaa.gov/product.php?site=NWS&issuedby=MTR&product=AFD&format=CI&version=1&glossary=0
//
// To find your local NWS office code for $myNWS, do this:
//   go to www.weather.gov
//   search for your city, state
//   look at the URL in the 'Forecast Discussion' link near the bottom of the page
//   use the 3-character abbreviation is in the &issuedby=XXX parameter on the 
//     Forecast Discussion link (XXX will be your local office)
//   put the XXX in the $myNWS variable below
//
// output: creates XHTML 1.0-Strict HTML page (default)
// Options on URL:
//      inc=Y    -- returns only the body code for inclusion
//                         in other webpages.  Omit to return full HTML.
// example URL:
//  http://your.website/forecast-discussion.php?inc=Y
//  would return data without HTML header/footer 
//
// Usage:
//  you can use this webpage standalone (customize the HTML portion below)
//  or you can include it in an existing page:
//  no parms:  $doIncludeFD = true; include("forecast-discussion.php"); 
//  parms:    include("http://your.website/forecast-discussion.php?inc=Y");
//  parms:    include("http://your.website/forecast-discussion.php?inc=Y");
//
//
// settings:  
//  change myNWS to abbreviation for your local NWS office
//    other settings are optional
// 
  
$myNWS 'BGM';   // Tucson, AZ
//  $myNWS = 'PQR';   // Portland, OR
//  $myNWS = 'OAX';   // Omaha, NE (Carter Lake, IA)
//
  
$cacheName "forecast-summary.txt";  // used to store the file so we don't have to
//                          fetch it each time
  
$refetchSeconds 1;     // refetch every nnnn seconds
// end of settings

// Constants
// don't change $fileName or script may break ;-)
  
$fileName "http://forecast.weather.gov/product.php?site=NWS&issuedby=BGM&product=AFD&format=txt&version=1&glossary=0&highlight=off";
// end of constants

// ------ start of code -------
if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
   
$filenameReal __FILE__;
   
$download_size filesize($filenameReal);
   
header('Pragma: public');
   
header('Cache-Control: private');
   
header('Cache-Control: no-cache, must-revalidate');
   
header("Content-type: text/plain");
   
header("Accept-Ranges: bytes");
   
header("Content-Length: $download_size");
   
header('Connection: close');
   
readfile($filenameReal);
   exit;
}

// Check parameters and force defaults/ranges
if ( ! isset($_REQUEST['inc']) ) {
        
$_REQUEST['inc']="";
}
if (isset(
$doIncludeFD) and $doIncludeFD ) {
  
$includeMode "Y";
 } else {
  
$includeMode $_REQUEST['inc']; // any nonblank is ok
}

if (
$includeMode) {$includeMode "Y";}

if (isset(
$_REQUEST['cache'])) {$refetchSeconds 1; }

// omit HTML <HEAD>...</HEAD><BODY> if only tables wanted
// --------------- customize HTML if you like -----------------------
if (! $includeMode) {
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Refresh" content="300" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Forecast Discussion for <?php print $myNWS ?> NWS Office</title>
</head>
<body style="background-color:#FFFFFF;">
<?php
}

// ------------- code starts here -------------------
echo "<!-- $Version -->\n";

// refresh cached copy of page if needed
// fetch/cache code by Tom at carterlake.org

if (file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds time()) {
      print 
"<!-- using Cached version of $cacheName -->\n";
      
$html implode(''file($cacheName));
    } else {
      print 
"<!-- loading $cacheName from $fileName -->\n";
      
$html fetchUrlWithoutHangingFD($fileName);
      
$fp fopen($cacheName"w");
  if ($fp) {
        
$write fputs($fp$html);
         
fclose($fp);  
         print 
"<!-- cache written to $cacheName. -->\n";
  } else {
     print "<!-- unable to save cache to $cacheName. -->\n";
  }
}
  
// extract the forecast discussion
 
preg_match('|<pre[^>]*>(.*)</pre>|Usi',$html,$matches);
 
$discussion $matches[1]; // now have the forecast as a string with \n delimiters

$discussion  trim($matches[1]); // prevent extra white space at beginning and end
$discussion str_replace(array("\r""\n"), ' '$discussion); //delete the linefeeds in the middle
$sstring 'SYNOPSIS'// start of synopis quick text
$estring '&&'// first divider
$start strpos($discussion,$sstring); // starting position of where to keep
$end strpos($discussion,$estring); // end of where to keep
$discuss substr($discussion$start+0, ($end-1-$start)); // new text (too long to print in cell format)
$charwrap round($pagewidth/7.25);
$discussion wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.

 // uncomment next line if you like only lower case text, or it could be made an option
//  $discussion  = strtolower(trim($matches[1]));

 
  
if ($discussion  == '') {
           
$discussion  'Forecast discussion unavailable, please try later.';
  }
  print 
"<pre>\n";
  print 
htmlspecialchars(strip_tags($discussion));
  print 
"</pre>\n";  
// print footer of page if needed    
// --------------- customize HTML if you like -----------------------
if (! $includeMode ) {   
?>


</body>
</html>

<?php
}

// ----------------------------functions ----------------------------------- 
 
 
function fetchUrlWithoutHangingFD($url// thanks to Tom at Carterlake.org for this script fragment
   
{
   
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
   
$numberOfSeconds=4;   

   
// Suppress error reporting so Web site visitors are unaware if the feed fails
   
error_reporting(0);

   
// Extract resource path and domain from URL ready for fsockopen

   
$url str_replace("http://","",$url);
   
$urlComponents explode("/",$url);
   
$domain $urlComponents[0];
   
$resourcePath str_replace($domain,"",$url);

   
// Establish a connection
   
$socketConnection fsockopen($domain80$errno$errstr$numberOfSeconds);

   if (!
$socketConnection)
       {
       
// You may wish to remove the following debugging line on a live Web site
          
print "<!-- Network error: $errstr ($errno) -->\n";
       }    
// end if
   
else    {
       
$xml '';
       
fputs($socketConnection"GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nCache-Control: no-cache, must-revalidate\r\nCache-control: max-age=0\r\nConnection: close\r\nUser-agent: Forecast loader script\r\nAccept: text/plain,text/html\r\n\r\n");
       
// Loop until end of file
       
while (!feof($socketConnection))
           {
           
$xml .= fgets($socketConnection4096);
           }    
// end while

       
fclose ($socketConnection);

       }    
// end else

   
return($xml);

   }    
// end function
   
// --------------end of functions ---------------------------------------

?>

ok i did and now it is long

also I am with 1and1.com now how do i get cumulus to upload without using port 22 which is secure..
Mike K.
Davis Vantage Vue 6250 - CumulusMX (3.21.1-b3205)
Gosport, Indiana
Gosportwx.com twitter.com/GosportINWX
-----------------------------------------------------------

 

anything