Today in Weather History Script

Poof… Just like magic it is all better today. :slight_smile:

This script only pulls the data once a day and stores it in a cache file. Maybe the site was having some issues when the cache was populated. Glad it sorted itself out.

Mine fixed itself also.

With the help of a friend , the script has been updated so that if the source is not available, the script will attempt to populate the cache again at the next page refresh/visit after 10 seconds.

Find this:

//   open the cache file and write the new data and then close the file.
if ($cacheDate !== $dateToday){
   $filecontents = implode(' ', file($urlfile)); 
   $fp2 = fopen($cacheFile, 'w');
   fwrite($fp2, $filecontents);
   fclose($fp2);
   echo "<!-- The cache date ($cacheDate) is not equal to today's date ($dateToday) and fresh data re-wrote the cache file -->\n";
} else {
   echo "<!-- The cache date ($cacheDate) is still equal to today's date ($dateToday) and fresh data was NOT written to the cache file -->\n";
// Open the cache file, read it, then close it   
    $handle7 = fopen($cacheFile, "r");
    $filesize = filesize($cacheFile);
    $filecontents = fread($handle7, $filesize);
    fclose($handle7);
}

and insert this just below:

if(preg_match('|Error: Cannot find events: No data available|Uis',$filecontents )){
  echo "<!-- The file did not contain events. A second attempt was made -->\n";
  sleep(10);
  $fp2 = fopen($cacheFile, 'w');
  $filecontents = implode(' ', file($urlfile));
  fwrite($fp2, $filecontents);
  fclose($fp2);
}

I’ve also updated the download from the first post.

Cheers,
Michael

Michael,
Thanks for update.

OT
How do you generate the tropical activity alert on your site?

New “Today in Weather History” script now available.

Version 3 is now available. This version uses an alternative source if in primary source fails. Additionally, this version has a lot of easy features for implementation.

The full daily history page can be seen in action at http://www.relayweather.com/wxOnThisDayUS.php
The random daily history can be seen in action at the bottom of the dashboard at http://www.relayweather.com/

Download:
The files are available at http://www.relayweather.com/downloads.php

Enjoy!

Michael
http://www.relayweather.com

Usage:

Insert the following where you want the history to appear:

Upload content in zip file and create/upload a blank file called wxDailyHistoryCache.php (this will hold the cache data on a daily basis)

Use Example for Full History: <?php include("include-dailyhistory.php"); print $fullHistory; ?>

Use Example for Random History (Use on dashboard or mainpage): <?php include("include-dailyhistory.php"); print $randomHistory; ?>

After intial installation, it may be necessary to force an update of the cache file as it only populates once a day.
Examples: http://www.yoursite.com/?forceupdate=1 or http://www.yoursite.com/yourfullhistorypage.php?forceupdate=1

works good… thanks for the update.

Thanks for the update Michael.

I was wondering why I am only showing 2 significant weather events on this date when all others I seen running the script have about 8.

Additionally the “credit” line is not printing leading me to believe the script is crashing before completion.

direct URL to see the script in action: http://www.k3jae.com/wxDailyHistory.php

It’s missing items from the beginning too :?

Have you tried deleting your cache file and making a new one? What version of the script are you using?

I just installed it today so everything is fresh. The cache file was empty when I uploaded it (created).

Unsure the version as it was whatever was on the DL link.

Could it be that you are using the random rather than full history option?

Use Example for Random History (Use on dashboard or mainpage): <?php include("include-dailyhistory.php"); print $randomHistory; ?>

Yep, that was it… DUH!!! :oops: Thanks, problem resolved.

Needed to use: <?php include("include-dailyhistory.php"); print $fullHistory; ?>

It should still print the source acknowledgement, maybe that’s a little bug for Michael to look at?

If you are referring to my site… Mine is giving the source???

Sorry if that was confusing, I mean the source of the data, what you called the credit line, which wasn’t showing when the site was showing the random version.

The script should be showing the credit line…

Do you still have an issue?

I’m new to the PHP thing…

Is there a template file that calls out the “include-dailyhistory.php” file we can use?

Here is mine attached.

Double check for settings that may need set for your particular setup.

Don’t forget to remove the .TXT at end of file.


include-dailyhistory.php.txt (8.85 KB)