Premise [download] Module: Environment Canada Weather

Motorola Premise

123

Senior Member
File Name: Module: Environment Canada Weather
File Submitter: 123
File Submitted: 19 Oct 2009
File Updated: 20 Oct 2009
File Category: Premise
Author: 123
Contact: PM me
Version: 1.2

Environment Canada Weather Module

This Module acquires weather data from Environment Canada's Forecast Data (XML) and displays it in Premise Browser. It shows the current weather, seven-day forecast, historical (almanac), an animated weather map (sourced from the Weather Channel), sunrise/set, and moonrise/set. Use of this module indicates acceptance of Environment Canada's Terms and Conditions (http://www.msc-smc.ec.gc.ca/commercial/licence_d3_site_XML.txt).

Installation
Install the EnvironmentCanada weather icons.
  • Create the following folder: c:\Program Files\Premise\SYS\web\Images\WeatherOffice.
  • Copy all EnvironmentCanada weather icons (GIF files) to the new folder.
Install the database file.
  • Copy "WeatherOffice.mdb" to: c:\Program Files\Premise\SYS\schema\modules.
Install the WeatherOffice CSS file.
  • Copy "weatheroffice.css" to c:\Program Files\Premise\SYS\web.
  • Navigate to c:\Program Files\Premise\SYS\web.
  • Copy "global.css" to "global_ORIGINAL.css" (i.e. make a backup)
  • Right-click "global.css", select Properties, disable Read-only , and click OK.
  • Using Notepad, open global.css and add the following to the top of the file (i.e. make it the new first line):
    @import url("weatheroffice.css");
  • Save the file and exit Notepad.
  • Right-click "global.css", select Properties, enable Read-only, and click OK.
Restart Premise's web server so that it reloads all CSS data.
  • Ensure you are running Builder on the Premise Server machine.
  • In Builder's Shortcut bar, click WebServer.
  • In the Properties window, locate the Status property.
  • Disable it, pause a few seconds, then enable it.
Import the Modules.
  • Using Builder's main menu, click File > Import, select Globals.xdo and click OK.
  • Repeat the previous step for EnvironmentCanada.xdo.
Add a WeatherOffice object to Premise Home.
  • In Builder's Shortcut bar, click Home.
  • In the Explorer window, right-click Home and select New > WeatherOffice.
  • In the Properties window, locate the City property.
  • Select the desired City.
  • Click the Update property.
  • The Status field will display "Acquiring weather data ...".

Customization
The Module contains a list of major Canadian cities. If your home town is not in the list, you can append it provided that Environment Canada has Forecast Data for it.

Find your city in the following list: [URL="http://dd.weatheroffice.gc.ca/citypage_wea...st_e_towns.html"]http://dd.weatheroffice.gc.ca/citypage_wea...st_e_towns.html[/URL]
Each city has a unique eight-character code consisting of the letter "s" followed by seven digits. For example, Montreal's code is "s0000635" and you only need the significant digits. For example, it is "635" for Montreal, "458 for Toronto ("s0000458"), and "47" for Calgary ("s0000047").
You may need to modify the city's name so that it complies with Visual Basic's naming rules for variables. For the purposes of this Module, the city's name should consist of nothing more than letters, hyphens, and underscores. It must not contain accented characters, apostophes, parentheses, punctuation, and it cannot start with a numeric value (so "100 Mile House" must be converted to "OneHundredMileHouse"). Here are a few conversion examples:
"Saint John's" -> "SaintJohn_s"
"St. Catharines" -> "StCatharines"
"St. Peter's" -> "StPeters"
"Rivière-du-Loup" -> "Riviere-du-Loup"
"Ottawa (Kanata - Orléans)" -> "Ottawa_Kanata-Orleans"

Let's assume the home town is "Kananaskis (Nakiska Ridgetop)" in Alberta (AB) whose code is "s0000263". We convert this to "Kannaskis_NakiskaRidgetop" with a code of "263".
  • In Builder, click Modules in the Shortcut bar.
  • Navigate to Modules/EnvironmentCanada/Classes/CityList
  • You can right-click CityList and select New > Enum or simply modify the existing "Saint-Hyacinthe_QC" entry.
  • Set the Name property must be in the following format: "CityName_ProvinceCode". Our example entry will be: "Kannaskis_NakiskaRidgetop_AB".
  • Set the DisplayName property must be in the following format: "CityName ProvinceCode". Our example entry will be: "Kannaskis_NakiskaRidgetop AB".
  • Set the Value property to: 263.
  • For cosmetic purposes, you can drag "Kannaskis_NakiskaRidgetop_AB" and drop it after "Halifax_NS" so that the city list is in sorted order.

If you wish to change the displayed data's appearance, you'll need to edit "WeatherOffice.css". You'll need to understand Cascading Style Sheets (CSS) in order to make any sense of the file.

Notes
Environment Canada's Forecast Data is in XML format and provides a large amount of detailed weather data (far more than its RSS feed). Environment Canada's web-site uses a set of 44 icons to represent over 300 weather conditions. However, the Forecast Data does not specify the icon to use in order to visually represent the weather conditions. For example the icon for "Sunny" is "00.gif" but Forecast Data does not specify this information. In addition, there is no master cross-reference list indicating the correspondence between forecast and icon.

"WeatherOffice.mdb" is a cross-reference list I've built by observing the daily weather and the icons used on Environment Canada's web-site. The list is incomplete and not a perfect match with EC's web-site. There are several weather conditions that I've never observed so I don't know which icon should be used. In addition, EC employs heuristics to select the best icon to represent the weather conditions. For example, it the forecast is Rain but with a chance of thundershowers then they will not simply choose the "rain" icon but will use the "rain with lightning bolt" icon. However, the threshold for this choice is not published so I don't when they will/will not choose the "thunderbolt" version. As a result, this Module simply uses the "rain" icon even if there is a chance of thundershowers.

If this Module encounters a known weather condition (listed in WeatherOffice.mdb), say "Chance of drizzle mixed with freezing drizzle", but does not know the correct icon, it will display a custom icon "100.gif" which is simply an exclamation mark. You'll have to go to Environment Canada's web-site, look at the seven-day forecast, right-click the icon they are currently using to represent the weather condition and read the corresponding number. For example, it is "08" for "Chance of flurries". in this case, let's say it is "28". You'd edit the Icon table in WeatherOffice.mdb, locate "Chance of drizzle mixed with freezing drizzle" and replace "100" in the Code field with "28". This is how I arrived at the existing entries in WeatherOffice.mdb (you're welcome!). Some icons are used exclusively for depicting the weather at night. This is handled by checking the "IsNight" field in the database.

If this Module encounters an unknown weather condition (not listed in WeatherOffice.mdb), say "Chance of frozen flying squirrels", it will display custom icon "99.gif" which is a question mark. You'll probably never see this icon (maybe).

The Forecast Data also provides Weather Watches whose details are not in the XML feed. Fortunately, it does provide a URL to a details page but in HTML, not XML, format. The Module follows the URL to the HTML page, extracts the relevant Weather Watch information and displays it in Premise Browser below the seven-day forecast. Be aware that extracting the Weather Watch details from the HTML page can fail if Environment Canada alters the page's formatting (this has happened).

Environment Canada has changed Forecast Data twice in the past year. It has increased it from a five to seven day forecast and changed the URL of the XML feed. Be aware that other changes in the future can cause problems for the Module.

ADDENDUM
Version 1.2 employs a more sophisticated means of extracting the details of a Weather Warning. It should prove to be more reliable because it can handle several HTML Heading tags (i.e. h1 through h9).

Click here to download this file
 
Thanks very much for supplying this code and for the time involved to properly document this.

I'll test it out this evening.
 
You're welcome!

I wasn't planning to share this Module so it took me awhile to identify all of its parts and document the installation process. Let me know if it fails to work, or exhibits bad behaviour, and I'll help you fix the problem.

I overlooked to mention that the Module includes a 30-minute Timer in order to periodically update the weather data. I believe it will self-activate the moment the EC Module is imported. You may need to customize the timer's PropertyChange script.
  • In Builder, click Modules in the Shortcut Bar.
  • Navigate to Modules/EnvironmentCanada/Timers/UpdateWeatherOffice/OnChangeTrigger
The OnChangeTrigger script contains the following:
Code:
debugout this.Name & ", " & now
on error resume next
if not Home.WeatherOffice is nothing then Home.WeatherOffice.Update = true
on error goto 0
You needn't change anything if you've created a Home.WeatherOffice object. If you've called it something else ("WeatherForecast") or you've created it in another location (i.e. Home.Yard.WeatherForecast) then you'll need to edit the script and replace "Home.WeatherOffice" with whatever you're currently using.

NOTE
The basics of a Weather Warning are contained in the Forecast Data XML feed and can be collected reliably. The details lie in an HTML page whose formatting is not designed for automated extraction.

I just noticed that the extraction technique I'm using to get the details of a Weather Warning is not working correctly in V1.1. Currently, the only Weather Warning in Canada is for the Queen Charlotte Islands. I checked the weather for the town of Sandspit and the Module was unable to extract the Weather Warning details from the associated HTML page. There appears to be some degree of variability in the HTML formatting tag used in the page and that makes it a moving target. It worked for me recently for a frost warning in Montreal but now it fails for Sandspit.

Version 1.2 now uses a more sophisticated extraction technique that *should* match any HTML heading tag (i.e. "<h1>", "<h2>", etc).
 
I installed this last night and it appears to be working flawlessly. Bear in mind that we didn't have any "Weather Warnings" in Calgary so I could not test that functionality.

The current timer is updated in 30 minute intervals from the time of import.

I'll update to 1.2 and keep you apprised.

Thanks again!
 
Glad to hear it!

To upgrade from V1.1. to V1.2:
  1. Using Builder, click Modules in the Shortcut bar.
  2. Delete Modules > EnvironmentCanada. This step will also delete the WeatherOffice object in Premise Home.
  3. Delete Modules > Plugins > Selectors > WeatherOffice.
  4. Import EnvironmentCanada_V1-2.xdo.
Proceed to create a WeatherOffice object in Premise Home and set the City property to your home town (i.e. Calgary).

V1.2 contains:
  • A revised version of Modules > EnvironmentCanada > Classes > WeatherOffice > GetWarningMessage.
    This is the function that extracts the details of a Weather Warning from an HTML page.
  • Revised Descriptions for the entries found in Modules > EnvironmentCanada > Classes > WarningTypes.
    This is an enumeration that lists the types of Weather Warnings and how they appear in the HTML page.
 
It appears that Environment Canada has recently updated the schema for its XML-based weather data. I noticed a new property called "iconCode" and it explicitly indicates which icon should be used to represent a given weather condition. For example, "00.gif" is used for "Sunny".

This is a long awaited enhancement and it allows me to dispense with the cross-reference table I had (painstakingly) created. With 300 defined weather conditions sharing 44 icons, it was a nearly impossible to build a complete table based on observations of Environment Canada's site! I've modified the module and will post it in a few days.
 
I hadn't really paid much attention to this, given my California location...BUT, I was thinking..you created a DB file? Access? As I was wishing my Mother Happy Birthday, I was thinking that a db of family & friends & holidays in a DB would be a great way to pop up additional data with the date/time/temperature...

So, I'll dig a bit on your work and see how you tied the db in....
 
Chuck,

If you're willing to wait a few days, you can be the first to test-drive my Newscaster module. I briefly described Newscaster in the middle of this post.

Newscaster has been working in my home for over a year but I've been too busy/lazy to document and post it. I now have most of it documented and I simply need to test the installation process to ensure I haven't overlooked anything. I hope to have it out the door next week.

Newscaster stores its "News Events" in Premise's Media folder (visible in Premise Browser) and does not use an external MDB file.

I have it read a newscast every morning through an Audrey. The newscast includes the daily weather (extracted from my Environment Canada and Personal Weather Underground modules but it can be adapted to work with John's XML Weather module) and any birthdays, anniversaries, tasks, appointments, etc for the current day.
 
My beta test unit is standing by!

Sounds awesome! Interested on how you tied this into the Premise Media Folder...
 
Back
Top