deformed-offering

Weather station scripts

They're free, but use at your own risk

The scripts 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 weather station website.
RSS feed for Scripts Updates A RSS Feed is available to help keep you informed on updates to the scripts.

If you find one or more of the scripts useful to you, please consider making a donation to help offset the routine expenses of operation of this website.
Thanks for your kind support!

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 and Weather-Watch forums and saratogaWXPHP Twitter account as they become available.

This page was updated Saturday, 01-Nov-2014 3:12 PM

WeatherUnderground International forecast formatting script - multilingual

Note: on 29-Oct-2014, WeatherUnderground changed their page layout for forecasts and necessitated a fairly complete rewrite of the WU-forecast.php script to Version 3.x. Since WeatherUnderground no longer includes forecast JSON data in the page, the V3.x script uses the WU API to get the forecast data for the script. To use it, you must acquire an API Key at http://www.wunderground.com/weather/api/.
Register for the Developer class key -- it is free/no-cost. The script will cache the JSON returns from the API so only one API access per forecast, per language is done per hour and that is well under the allowed accesses per day for the Developer class key.

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 saratoga (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.

Legal Stuff -- please read and heed...

Unlike the carterlake/NOAA forecast script which reads the public domain NWS websites, this script reads and processes the WU API JSON feed 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:

  1. Have your weather station submit data to WeatherUnderground as a WU member.
  2. Register for and acquire a free WU API key.
  3. Use this script ONLY on your personal, non-commercial weather station website.
  4. Leave attribution (and hotlink) to WeatherUnderground as the source of the data.

Adhere to these four requirements, and you should have fair use of this data from Weather Underground.

Settings in the WU-forecast.php script

// Settings ---------------------------------------------------------------
//REQUIRED: a WU API KEY.. sign up at http://www.wunderground.com/weather/api/
$WUAPIkey = 'specify-for-standalone-use-here'; // use this only for standalone / non-template use
// NOTE: if using the Saratoga template, add to Settings.php a line with:
//    $SITE['WUAPIkey'] = 'your-api-key-here';
// and that will enable the script to operate correctly in your template
//
$iconDir ='./forecast/images/';	// directory for carterlake icons './forecast/images/'
$iconType = '.jpg';				// default type='.jpg' 
//                            		use '.gif' for animated icons from http://www.meteotreviglio.com/
//$iconDir ='';					// set to '' to use the Wunderground icons instead
//
//
$WU_URL = 'http://www.wunderground.com/global/stations/06075.html';
//
// The optional multi-city forecast .. make sure the first entry is for the $WU_URL location
// The contents will be replaced by $SITE['WUforecasts'] if specified in your Settings.php

/*
$WUforecasts = array(
 // Location|forecast-URL  (separated by | characters)
'Saratoga|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=95070',
'Aarhus|http://www.wunderground.com/global/stations/06075.html',
'Auckland|http://english.wunderground.com/cgi-bin/findweather/getForecast?query=-36.910%2C174.771&sp=IAUCKLAN110', // Awhitu, Waiuku New Zealand
'Amsterdam|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Amsterdam%2C+Netherlands',
'Paris|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Paris%2C+France',
'Stockholm|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Stockholm%2C+Sweden',
'Oslo|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Oslo%2C+Norway',
'Moscow|http://www.wunderground.com/global/stations/27612.html',
'Athens|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Athens%2C+Greece',
'Tel Aviv|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Tel+Aviv%2C+Israel',
'Madrid|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Madrid%2C+Spain',
'Helsinki|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=Helsinki%2C+Finland',
'Castrop-Rauxel|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=51.572%2C7.376&sp=INORDRHE72',
'Southampton|http://www.wunderground.com/global/stations/03865.html',
'Canvey Island, Essex|http://www.wunderground.com/weather-forecast/zmw:00000.57.03691',
'Saratoga PWS|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=pws:KCASARAT1',
); 
//*/
//
$maxWidth = '640px';                      // max width of tables (could be '100%')
$maxIcons = 10;                           // max number of icons to display
$maxForecasts = 14;                       // max number of Text forecast periods to display
$maxForecastLegendWords = 4;              // more words in forecast legend than this number will use our forecast words 
$numIconsInFoldedRow = 5;                 // if words cause overflow of $maxWidth pixels, then put this num of icons in rows
$autoSetTemplate = true;                  // =true set icons based on wide/narrow template design
$cacheFileDir = './';                     // default cache file directory
$cacheName = "WU-forecast-json.txt";      // locally cached page from WU
$refetchSeconds = 3600;                   // cache lifetime (3600sec = 60 minutes)
$xlateCOP = 'Chance of precipitation';    // change to local language if needed like
//$xlateCOP = 'Kans op neerslag';   //  Dutch example
$showTempsAs  = 'C';                  // under icons/forecast, 'C'=Centigrade, 'F'=Fahrenheit
$charsetOutput = 'ISO-8859-1';        // default character encoding of output
$lang = 'en';	// default language
$foldIconRow = true;  // display icons in rows of 5 if long texts are found
$RTLlang = ',he,jp,cn,';  // languages that use right-to-left order
// ---- end of settings ---------------------------------------------------

For Saratoga template users, you normally do not have to customize the script itself as the most common configurable settings are maintained in your Settings.php file. This allows you to just replace the WU-forecast.php on your site when new versions are released. With V3.00, you DO have to add a $SITE['WUAPIkey'] = 'your-key-here'; entry to your Settings.php file to support this and future releases of the script.

$WUAPIkey = 'specify-for-standalone-use-here';
This setting is for standalone use (do not change this for Saratoga templates).
Register for a WU API Key at http://www.wunderground.com/weather/api/ and replace specify-for-standalone-use-herei> with the registered API key. The script will nag you if this has not been done.

For Saratoga template users, do the registration at the WU API site above, then put your API key in your Settings.php as:

$SITE['WUAPIkey'] = 'your-key-here';

to allow easy future updates of the WU-forecast.php script by simple replacement.
$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 file path to the Saratoga 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.
Saratoga template users: Use the Settings.php entry for $SITE['fcsticonsdir'] to specify this value.
$iconType
This setting controls the extension (type) for the icon to be displayed.
='.jpg'; for the default Saratoga JPG icon set.
='.gif'; for the Meteotriviglio animated GIF icon set.
Saratoga template users: Use the Settings.php entry for $SITE['fcsticonstype'] to specify this value.
$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. 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.
Saratoga template users: Use the Settings.php entry for $SITE['fcsturlWU'] to specify this value.
$WUforecasts = array(
// Location|forecast-URL (separated by | characters)
'Saratoga|http://www.wunderground.com/cgi-bin/findweather/getForecast?query=95070',
...
);
This setting is an alternative method of specifying the locations for forecasts. If used, it will override the main location specified in the $WU_URL above and allow the viewer to choose between forecasts for different areas based on a drop-down list box selection.
Saratoga template users: Use the Settings.php entry for $SITE['WUforecasts'] = array(...); to specify the list of sites and URLs.
$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 Saratoga/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.
$cacheFileDir
This setting specifies the directory to store the cache files. The default is the same directory in which the script is located.
Include the trailing slash in the directory specification.
Saratoga template users: Use the Settings.php entry for $SITE['cacheFileDir'] to specify this value.
$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 3600 seconds (60 minutes). Forecasts don't change very often, so please don't reduce it below 60 minutes to minimize your API access count and keep it to the free Developer API range.
$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
Saratoga template users: Use the Settings.php entry for $SITE['xlateCOP'] to specify this value.
$showTempsAs
This setting controls how the temperatures are displayed below the condition icons.
='C' will display temperatures in Centigrade below the icons and metric units (C,km/s,hPa,mm) in the text forecast. (Default)
='F' will display temperatures in Fahrenheit below the icons and imperial units (F,mph,inHg,in) in the text forecast.
Saratoga template users: This setting will be overridden by the default temperature units specified in your Settings.php.
$foldIconRow
This setting controls 'folding' of the icons into two rows if the aggregate width of characters exceeds the $maxSize dimension in pixels.
= true; is the default (fold the row)
= false; to select not to fold the row.
Saratoga template users: Use the Settings.php entry for $SITE['foldIconRow'] to specify this value.

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"); ?>

 

WeatherUnderground 7-day Forecast: Aarhus
Friday Friday Night Saturday Saturday Night Sunday Sunday Night Monday Monday Night Tuesday Tuesday Night
Partly cloudy skies Chance rain Chance rain Chance rain Rain Chance rain Partly cloudy Clear skies A mainly sunny sky A few clouds
Partly cloudy skies Chance rain Chance rain Chance rain Rain Chance rain Partly cloudy Clear skies A mainly sunny sky A few clouds
61°F 47°F 63°F 48°F 58°F 49°F 60°F 45°F 58°F 45°F

 

Friday
 
Partly cloudy skies. Slight chance of a rain shower. High 61F. Winds WSW at 15 to 25 mph.
Friday Night
 
Showers in the evening, then clearing overnight. Low 47F. Winds WSW at 10 to 15 mph. Chance of rain 30%.
Saturday
 
Partly cloudy skies during the morning hours will give way to occasional showers in the afternoon. High 63F. Winds SSW at 5 to 10 mph. Chance of rain 60%.
Saturday Night
 
Overcast with rain showers at times. Thunder possible. Low 48F. Winds light and variable. Chance of rain 50%.
Sunday
 
Rain. High 58F. Winds NNE at 5 to 10 mph. Chance of rain 100%. Rainfall around a half an inch.
Sunday Night
 
Showers in the evening with some clearing overnight. Low 49F. Winds N at 5 to 10 mph. Chance of rain 70%.
Monday
 
Partly cloudy. High near 60F. Winds N at 10 to 15 mph.
Monday Night
 
Clear skies. Low around 45F. Winds NNE at 5 to 10 mph.
Tuesday
 
A mainly sunny sky. High 58F. Winds ENE at 5 to 10 mph.
Tuesday Night
 
A few clouds. Low near 45F. Winds E at 5 to 10 mph.
Wednesday
 
Considerable cloudiness. High 56F. Winds E at 10 to 15 mph.
Wednesday Night
 
Cloudy. Low 46F. Winds ENE at 5 to 10 mph.
Thursday
 
Partly cloudy. High 58F. Winds ENE at 10 to 15 mph.
Thursday Night
 
Partly cloudy skies. Low 49F. Winds ENE at 5 to 10 mph.

 

Forecast from WeatherUnderground for Aarhus.

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>
Friday
Partly cloudy skies
Partly cloudy skies
Friday Night
Chance rain
Chance rain
61°F47°F

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>

Friday
Partly cloudy skies
Partly cloudy skies
61°F
Partly cloudy skies. Slight chance of a rain shower. High 61F. Winds WSW at 15 to 25 mph.
Friday Night
Chance rain
Chance rain
47°F
Showers in the evening, then clearing overnight. Low 47F. Winds WSW at 10 to 15 mph. Chance of rain 30%.

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 (ML Version 3.02 - 01-Nov-2014 for old WD/PHP/World-ML or Base-World template set)
Note: as of ML Version 1.26, the script should be usable for Standalone or old WD/PHP/World V2 template use also.
Note: as of V2.00, the script requires PHP 5.3+ to operate correctly.

Download: Icon Set (upload to your website in the /forecast/images directory)

deformed-offering