项目作者: ktrue

项目描述 :
Environment Canada Lightning Danger script
高级语言: PHP
项目地址: git://github.com/ktrue/EC-lightning.git
创建时间: 2019-05-05T01:01:31Z
项目社区:https://github.com/ktrue/EC-lightning

开源协议:GNU General Public License v3.0

下载


Environment Canada Lightning Danger script (for www.weatheroffice.ec.gc.ca)

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:



id=AAA


If present, the script will load lightning map images from the ‘AAA’ lightning site. The available lightning maps are:

id=NAT - National lightning (script default $lightningID)

id=PAC - Pacific region lightning

id=WRN - Prairies region lightning

id=ONT - Ontario region lightning

id=QUE - Quebec region lightning

id=ATL - Atlantic region lightning


lang=en


(Default) Text is in English..


lang=fr


Text is in French .


play=yes


(default)—Start the JavaScript animation when page is loaded.


play=no


Don’t start the animation when the page is loaded. Viewer must press play-stop button to start animation.


imgonly=Y


Return a 1/4 size static image of the latest lightning selected.
This is for use in an statement on your page.
See example 1 below for usage.

Note: the small lightning map images are width=”290” and vary in height.


For webmaster help with debugging the setup/configuration of the script, the following parameters may also be used:



cache=no


Forces refresh of EC lightning page and lightning map images .


Settings inside the script

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.

  1. // Settings:
  2. // --------- start of settings ----------
  3. //
  4. // Go to http://weather.gc.ca/lightning/index_e.html
  5. // Click on the desired area page.
  6. // You should see a lightning page with an url like
  7. // http://weather.gc.ca/lightning/index_e.html?id=XXX
  8. // copy the three letter area id=XXX into $lightningID = 'XXX'; below
  9. //
  10. $lightningID = 'NAT'; // set to default Site for lightning (same as id=xxx on EC website)
  11. // // available sites: NAT ARC PAC WRN ONT QUE ATL
  12. $defaultLang = 'en'; // set to 'fr' for french default language
  13. // // set to 'en' for english default language
  14. //
  15. $lightningCacheName = 'ec-lightning.txt'; // note: will be changed to -en.txt or
  16. // -fr.txt depending on language choice and stored in $lightningDir
  17. $lightningDir = './radar/'; // directory for storing lightning-XXX-0.png to lightning-XXX-6.png images
  18. // note: relative to document root.
  19. $lightningWidth = 620; // width of images to output in pixels. default=620
  20. //
  21. $refetchSeconds = 300; // look for new images from EC every 5 minutes (300 seconds)
  22. // NOTE: EC may take up to 20 minutes to publish new images
  23. $noLightningMinutes = 25; // minutes to wait before declaring the image site as 'N/O -not operational'
  24. //
  25. $aniSec = 1; // number of seconds between animations
  26. //
  27. $charsetOutput = 'ISO-8859-1'; // default character encoding of output
  28. // ---------- end of settings -----------

Example 1 - Current default lightning small image

  1. <img src="http://your.website.com/ec-lightning.php?imgonly=Y"
  2. width="290" height="240"
  3. alt="Latest Canada lightning from Environment Canada"
  4. title="Latest Canada lightning from Environment Canada" />

Results in:

sample small image

Example 2 - Canada National Lightning in French

  1. <?php
  2. $doInclude = true;
  3. $doPrint = true;
  4. $doAutoPlay = true;
  5. $doLang = 'fr';
  6. include_once("ec-lightning.php");
  7. ?>

Results in a National lightning like this (in French):

sample output in french

Installation Instructions

  1. Upload ec-lightning-cachetest.php to your website (in your document root directory).
  2. If you are NOT already using the ec-radar.php script, then create a new ./radar/ directory on the webserver one directory below where you placed the script, and upload the legendLightning.png file to that directory.
  3. 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.

  4. Edit ec-lightning.php to change other settings ($lightningID) as you like.
  5. Upload ec-lightning.php to the same directory that successfully ran ec-lightning-cachetest.php.
  6. View ec-lightning.php with your browser. You should see the animation of your selected ($lightningID) lightning map.
  7. Install links in your other webpages for the lightning map images you desire.

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.