Environment Canada Lightning Danger script
This script will read the HTML from the Environment Canada Lightning Danger Map page (cached) and download/cache the lightning map images as .png files on your website. Since the EC uses lightning graphic names with embedded timestamps, this script offers one of the few ways that weather enthusiasts can include EC lightning map images in their own websites.
The ec-lightning.php script uses a subdirectory (./radar/ default) to store the contents of the EC lightning HTML pages and the current lightning graphics. For proper operation of the script, you need to ensure that the cache directory is writable by PHP scripts. A simple test script is included to check this (ec-lightning-cachetest.php).
The script will load the HTML page from the EC website, cache it, and parse the contents for the lightning graphic images available, then download, resize and cache the images in ./radar/lightning-AAA-N.png files (AAA=siteid, N=0 (oldest) to 6 (most recent). Then the script will generate HTML and JavaScript to display the graphics from the cache and the associated date stamps for the lightning map images. The script generates uniquely named JavaScript functions/variables to allow you to embed more than one Lightning set on a page (as shown below). A smaller (1/4 size) image is also available of the most recent lightning map image as ./radar/lightning-AAA-sm.png. The following parameters are available on the ec-lightning.php script:
For webmaster help with debugging the setup/configuration of the script, the following parameters may also be used:
If you create a writable /lightning subdirectory in the document root of your webserver, then the only settings you should change are $siteID and $defaultLang.
// Settings:
// --------- start of settings ----------
//
// Go to http://weather.gc.ca/lightning/index_e.html
// Click on the desired area page.
// You should see a lightning page with an url like
// http://weather.gc.ca/lightning/index_e.html?id=XXX
// copy the three letter area id=XXX into $lightningID = 'XXX'; below
//
$lightningID = 'NAT'; // set to default Site for lightning (same as id=xxx on EC website)
// // available sites: NAT ARC PAC WRN ONT QUE ATL
$defaultLang = 'en'; // set to 'fr' for french default language
// // set to 'en' for english default language
//
$lightningCacheName = 'ec-lightning.txt'; // note: will be changed to -en.txt or
// -fr.txt depending on language choice and stored in $lightningDir
$lightningDir = './radar/'; // directory for storing lightning-XXX-0.png to lightning-XXX-6.png images
// note: relative to document root.
$lightningWidth = 620; // width of images to output in pixels. default=620
//
$refetchSeconds = 300; // look for new images from EC every 5 minutes (300 seconds)
// NOTE: EC may take up to 20 minutes to publish new images
$noLightningMinutes = 25; // minutes to wait before declaring the image site as 'N/O -not operational'
//
$aniSec = 1; // number of seconds between animations
//
$charsetOutput = 'ISO-8859-1'; // default character encoding of output
// ---------- end of settings -----------
<img src="http://your.website.com/ec-lightning.php?imgonly=Y"
width="290" height="240"
alt="Latest Canada lightning from Environment Canada"
title="Latest Canada lightning from Environment Canada" />
Results in:
<?php
$doInclude = true;
$doPrint = true;
$doAutoPlay = true;
$doLang = 'fr';
include_once("ec-lightning.php");
?>
Results in a National lightning like this (in French):
Run ec-lightning-cachetest.php script from your browser.
If the ec-lightning-cachetest.php reports success in writing the file, finding the needed legendLightning.png and that GD is installed, then proceed to step 4.
If you have error messages appearing, then you’ll have to fix the problem on your webserver (by changing the permissions on the ./radar/ directory to 755, or 775 on Linux/Unix systems, or allowing ‘all’ to read/write/create on IIS system). The ec-lightning.php program requires the use of cache files, so you’ll have to get a clean run on ec-lightning-cachetest.php to have ec-lightning.php run successfully.
Note: this script is included with the AJAX/PHP Base-Canada template sets (English and bilingual English/French). It is also available (with instructions) at Saratoga Weather script page.