They're free, but use at your own risk
The scripts in PHP and Perl referenced here are used in the operation of this weather station, and may be freely copied and used to support your station. Please note that you use these scripts at your own risk. No warranty is expressed or implied. I accept no liability for any damages that may ensue from their use.
You will need to configure them for your own particular station website.
A RSS Feed is available to help keep you informed on updates to the scripts.
A Version History is available -- check back from time to time to see if there are updates to scripts you have downloaded earlier. Announcements of version updates and new scripts are made on WXForum.net , Weather-Watch, Ambient and Weather-Matrix forums as they become available.
This page was updated
Sunday, 30-Mar-2008 7:13 AM
WeatherUnderground international forecast formatting script - multilingual
I started this script based on a Perl script I had used to extract the Weather Underground forecast for my area to post on my original 1-page website. Thanks to interest from others to use a modified version of that script for international forecasts,
I thought it was a good idea to make WU forecast output available in multiple languages (since the WU site supports translations). I wrote the WU-forecast.php to create a carterlake-style forecast output that would use the carterlake (NOAA) icon set (or the WU Icon set), would be easy to include in a weather website, and have built-in support for translations to other languages based on those languages provided by WeatherUnderground.
PLEASE NOTE: This script does NOT work for locations in the United States, US Territories or Canada.
For USA locations, use the carterlake advforecast PHP script instead.
For Canadian locations use the EC-forecast.php PHP script instead.
Legal Stuff -- please read and heed...
Unlike the carterlake/NOAA forecast script which reads the public domain NWS websites, this script reads and processes a forecast page from WeatherUnderground.com, which contains copyrighted material. WU has a very stringent (and somewhat strident) Terms of Use that on first reading seems to prohibit any usage of their site, even by personal, non-commercial websites who's owners are contributing their weather data to Weather Underground. The ToS seems to prohibit even the common usage by VWS templates (and my AJAXed versions) which make extensive use of WU forecast, graphics and data in their design.
In a series of mail messages and forum postings, the intent of WU is to allow fair usage of their graphics and data for personal, non-commercial stations that contribute data to WeatherUnderground was stated. Here's the message with that information:
Hello,
My name is John Celenza and I am the Director of Weather Technology at Wunderground.
Please let me explain.
It is not Weather Underground's intention to disallow folks to use our graphics and data on their personal/non-commercial web sites.
Please feel free to use Wunderground images and data on personal sites, as long as you link those images to Wunderground or give direct credit. Something like "This image courtesy of Weather Underground" is appropriate.
We sincerely appreciate the contributions folks have made to our community. And, we are in no way an organization trying to take...take...take and not give. Our philosophy couldn't be farther from that.
Hopefully we can make the Terms of Service more clear soon.
Thank you!
-John
So, in order to use this script you need to:
- Have your weather station submit data to WeatherUnderground as a WU member.
- Use this script ONLY on your personal, non-commercial weather station website.
- Leave attribution (and hotlink) to WeatherUnderground as the source of the data.
Adhere to these three requirements, and you should have fair use of this data from Weather Underground.
Settings in the WU-forecast.php script
// Settings ---------------------------------------------------------------
$iconDir ='./forecast/images/'; // directory for carterlake icons './forecast/images/'
//$iconDir =''; // set to '' to use the Wunderground icons instead
//
// view the forecast you want on www.wunderground.com using the language setting you desire,
// then copy the FULL url to the $WU_URL setting below. Some examples are commented out below
//
$WU_URL = 'http://dutch.wunderground.com/cgi-bin/findweather/getForecast?query=Amsterdam%2C+Netherlands';
//
$maxWidth = '640px'; // max width of tables (could be '100%')
$maxIcons = 10; // max number of icons to display
// // rain icon, otherwise sky icon w/PoP displayed.
$cacheName = "WU-forecast.txt"; // locally cached page from WU
$refetchSeconds = 1800; // cache lifetime (1800sec = 30 minutes)
$xlateCOP = 'Chance of precipitation'; // change to local language if needed like
//$xlateCOP = 'Kans op neerslag'; // Dutch example
$showTempsAs = 'C'; // under icons, 'C'=Centigrade only, 'F'=Fahrenheit only, 'B' = both
// ---- end of settings ---------------------------------------------------
- $iconDir
-
This setting controls whether to display the NOAA-styled icons or the WeatherUnderground icons on the forecast display. Set $iconDir = ''; to use the WeatherUnderground icons.
Set $iconDir to the relative URL (and file) path to the carterlake Icon set (same set as used with the WXSIM plaintext-parser.php script). Be sure to include the trailing slash in the directory specification as shown in the example above.
- $WU_URL
- This is the full URL for the WeatherUnderground page containing the forecast. Find it by searching on WU for a nearby city to your weather station location. If you wish to use a different language, use the language selector on the left side of the WU page to select the desired language. Copy the full URL from your browser address bar to the area between the single quotes. Please note that some WU translations may be incomplete as not all words/phrases may be translated from English. Also note that changing from English may involve using different character sets than the ISO-8859-1 Latin set. The script will produce HTML with a <meta> tag specifying the character set -- if you include the script in a page, make sure the including page uses the character set of the WU page otherwise your output page may be garbled and unreadable.
- $maxWidth
- This variable controls the maximum width of the tables for the icons and text display. It may be in pixels (as shown), or '100%'. The carterlake/NOAA icons are 55px wide and there are up to 14 icons, so beware setting this width too small as the display may be quite strange.
- $maxIcons
- This variable specifies the maximum number of icons to display in the graphical part of the forecast. Some forecast locations may have up to 7 days of forecast (14 icons) so be careful how wide the forecast may become on the page.
- $cacheName
- This variable specifies the name of the cache file for the WU forecast page.
- $refetchSeconds
- This variable specifies the cache lifetime, or how long to use the cache before reloading a copy from Weather Underground. The default is 1800 seconds (30 minutes). Forecasts don't change very often, so please don't reduce it below 30 minutes to minimize the load on the WU servers.
- $xlateCOP
- This setting is used to replace the phrase 'Chance of precipitation' with the same phrase in your language. Currently, Wunderground doesn't have this phrase translated in the non-English websites
- $showTempsAs
- This setting controls how the temperatures are displayed below the condition icons.
'C' will display temperatures in Centigrade below the icons. (Default)
'F' will display temperatures in Fahrenheit below the icons.
'B' will display temperatures in Centigrade and Fahrenheit below the icons.
More documentation is contained in the script itself about variable names/arrays made available, and the contents. The samples below serve to illustrate some of the possible usages on your weather website.
Usage samples
<?php
$doIncludeWU = true;
include("WU-forecast.php");
?>
You can also include it 'silently' and print just a few (or all) the contents where you'd like it on the page
<?php
$doPrintWU = false;
require("WU-forecast.php"); ?>
then on your page, the following code would display just the current and next time period forecast:
<table>
<tr align="center" valign="top">
<?php print "<td>$WUforecasticons[0]</td><td>$WUforecasticons[1]</td>\n"; ?>
</tr>
<tr align="center" valign="top">
<?php print "<td>$WUforecasttemp[0]</td><td>$WUforecasttemp[1]</td>\n"; ?>
</tr>
</table>
Sunday
 Partly Cloudy | Sunday Night
 Clear |
| 12°C | 6°C |
Or if you'd like to include the immediate forecast with text for the next two cycles:
<table>
<tr valign="top">
<?php print "<td align=\"center\">$WUforecasticons[0]<br />$WUforecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WUforecasttext[0]</td>\n"; ?>
</tr>
<tr valign="top">
<?php print "<td align=\"center\">$WUforecasticons[1]<br />$WUforecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$WUforecasttext[1]</td>\n"; ?>
</tr>
</table>
Sunday
 Partly Cloudy 12°C |
Partly Cloudy. High: 53° F. / 12° C. Wind SSW 22 mph. / 36 km/h. |
Sunday Night
 Clear 6°C |
Clear. Low: 42° F. / 6° C. Wind SW 11 mph. / 18 km/h. |
If you'd like to style the output, you can easily do so by setting a CSS for class WUforecast either in your CSS file or on the page including the WU-forecast.php (in include mode):
<style type="text/css">
.WUforecast {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9pt;
}
</style>
Installation of WU-forecast.php
Download WU-forecast.php from the link below.
Optionally, download the Icon set (or just the Add-on Icons if you already have the Carterlake NOAA Icon set), and upload to /forecast/images directory. If you already have the plaintext-parser.php WXSIM script installed, you can use the existing icon set (no need to download again).
Change settings in WU-forecast.php for the $WU_URL address and the address of the icons if necessary and upload the modified WU-forecast.php to your website.
Ensure the permission on "WU-forecast.txt" cache file are at least 666 or 766 so the file is writable by the WU-forecst.php script
Download: WU-forecast.php (Version 1.05 -30-Mar-2008)
Download: Icon Set
(upload to your website in the /forecast/images directory)
Note: If you have the icon set from Tom ( http://members.cox.net/carterlakeweather/forecasticons.zip)
then please download Add-on Icons to Tom's set and upload to your /forecast/images directory.