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.

Many of these scripts are now available on GitHub at https://github.com/ktrue

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 Tuesday, 31-Mar-2020 12:10 PM

DarkSky International forecast formatting script - multilingual

This script was designed to replace the WU-forecast.php script as WeatherUnderground has announced the discontinuation of their API keys effective 31-Dec-2018. Since the source data for WU-forecast.php is being discontinued, the WU-forecast.php script is deprecated and will no longer function after that date.

Note that the DarkSky API only provides Daily forecasts, so no night-time forecast icons are available. While DarkSky provides international versions of the forecast, it is only one short sentence and used as the icon description. The DS-forecast-lang.php provides translation capabilities for Saratoga Template languages for additional text added to the text forecast from data provided by DarkSky API (i.e. Temperature High/Low, Probibility of precipation, Wind direction, speed and gust, UV index ). The DS-forecast-lang.php is provided as a separate script for easy update as new languages are added. Currently the following languages are supported (in addition to English: af,bg,cs,ct,de,dk,el,es,fi,fr,he,hu,it,nl,no,pl,pt,ro,se,si,sk,sr

NOTE: DarkSky was purchased by Apple on 31-Mar-2020 and has announced the end of 2021 to discontinue the public API and they are no longer offering API keys.
If you already have a DarkSky API key, this script will operate until the end of 2021.
If you do not already have an API key, do not install this script as it will not work for you.

In order to use this script you need to:

  1. Register for and acquire a free DarkSky API key.
    1. Browse to https://darksky.net/dev and sign in to acquire an API key (NO LONGER AVAILABLE after 31-Mar-2020, see above)
    2. insert the API key in $DSAPIkey in the DS-forecast.php script or as $SITE['DSAPIkey'] in Settings.php for Saratoga template users.
    3. Customize the $DSforecasts array (or $SITE['DSforecasts'] in Settings.php) with the location names, latitude/longitude for your forecasts. The first entry will be the default one for forecasts.
  2. Use this script ONLY on your personal, non-commercial weather station website.
  3. Leave attribution (and hotlink) to DarkSky as the source of the data in the output of the script.

Adhere to these three requirements, and you should have fair use of this data from DarkSky.

Settings in the DS-forecast.php script

// Settings ---------------------------------------------------------------
// REQUIRED: a darksky.net API KEY.. sign up at https://darksky.net/dev
$DSAPIkey = '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['DSAPIkey'] = '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 fromhttp://www.meteotreviglio.com/
//
// The forecast(s) .. make sure the first entry is the default forecast location.
// The contents will be replaced by $SITE['DSforecasts'] if specified in your Settings.php

$DSforecasts = array(
 // Location|lat,long  (separated by | characters)
'Saratoga|37.27465,-122.02295',
'Auckland|-36.910,174.771', // Awhitu, Waiuku New Zealand
); 

//
$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 = "DS-forecast-json.txt";      // locally cached page from DS
$refetchSeconds = 3600;                   // cache lifetime (3600sec = 60 minutes)
//
// Units: 
// si: SI units (C,m/s,hPa,mm,km)
// ca: same as si, except that windSpeed and windGust are in kilometers per hour
// uk2: same as si, except that nearestStormDistance and visibility are in miles, and windSpeed and windGust in miles per hour
// us: Imperial units (F,mph,inHg,in,miles)
// 
$showUnitsAs  = 'ca'; // ='us' for imperial, , ='si' for metric, ='ca' for canada, ='uk2' for UK
//
$charsetOutput = 'ISO-8859-1';        // default character encoding of output
//$charsetOutput = 'UTF-8';            // for standalone use if desired
$lang = 'en';	// default language
$foldIconRow = false;  // =true to display icons in rows of 5 if long texts are found
// ---- 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 DS-forecast.php on your site when new versions are released.
You DO have to add a $SITE['DSAPIkey'] = 'your-key-here'; and a $SITE['DSforecasts] = array( ...); entries to your Settings.php file to support this and future releases of the script.

$DSAPIkey = 'specify-for-standalone-use-here';
This setting is for standalone use (do not change this for Saratoga templates).
Register for a DarkSky API Key at https://www.darksky.net/account/create and replace specify-for-standalone-use-here 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 DarkSky API site above, then put your API key in your Settings.php as:

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

to allow easy future updates of the DS-forecast.php script by simple replacement.
$iconDir
This setting controls whether to display the NOAA-styled icons on the forecast display.
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.
 
$DSforecasts = array(
// Location|forecast-URL (separated by | characters)
'Saratoga|37.27465,-122.02295',
'Auckland|-36.910,174.771', // Awhitu, Waiuku New Zealand

...
);
This setting is the primary method of specifying the locations for forecasts. It allows 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['DSforecasts'] = 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 8 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 8 days of forecast (8 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 DS forecast page.
$refetchSeconds
This variable specifies the cache lifetime, or how long to use the cache before reloading a copy from DarkSky. 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.
$showUnitsAs
This setting controls the units of measure for the forecasts.
='si' SI units (C,m/s,hPa,mm,km)
='ca' same as si, except that windSpeed and windGust are in kilometers per hour
='uk2' same as si, except that nearestStormDistance and visibility are in miles, and windSpeed and windGust in miles per hour
='us' Imperial units (F,mph,inHg,in,miles)
Saratoga template users: This setting will be overridden by the $SITE['DSshowUnitsAs'] 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
$doIncludeDS = true;
include("DS-forecast.php"); ?>

 

Currently: Sat, 04-Apr-2020 9:03am PDT
Weather conditions at 0 km from forecast point.
Mostly Cloudy
Mostly Cloudy
Temperature: 8°C
Wind: S 6->10 km/h.
Humidity: 80%
Dew Point: 4°C
Barometer: 1014.1 hPa
Visibility: 16.1 km
UV Index: 1
Sunrise: 06:49
Sunset: 19:35
Light rain today through Tuesday.
DarkSky Forecast for: Saratoga, CA, USA
Updated: Sat, 04-Apr-2020 9:00am PDT

 

Daily Forecast

Saturday Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Light rain starting in the afternoon Light rain throughout the day Drizzle until afternoon, starting again overnight Mostly cloudy throughout the day Clear throughout the day Clear throughout the day Clear throughout the day Clear throughout the day
Light rain starting in the afternoon Light rain throughout the day Drizzle until afternoon, starting again overnight Mostly cloudy throughout the day Clear throughout the day Clear throughout the day Clear throughout the day Clear throughout the day
14°C
9°C
11°C
4°C
14°C
4°C
15°C
5°C
21°C
7°C
23°C
10°C
24°C
9°C
25°C
8°C


Saturday
 
Light rain starting in the afternoon. Chance of precipitation (rain) 80%. High: 14°C. Low: 9°C. Wind SSW 8->31 km/h. UV Index 4.
Sunday
 
Light rain throughout the day. Chance of precipitation (rain) 100%. High: 11°C. Low: 4°C. Wind SSW 12->41 km/h. UV Index 3.
Monday
 
Drizzle until afternoon, starting again overnight. Chance of precipitation (rain) 80%. High: 14°C. Low: 4°C. Wind NW 6->11 km/h. UV Index 3.
Tuesday
 
Mostly cloudy throughout the day. Chance of precipitation (rain) 40%. High: 15°C. Low: 5°C. Wind W 7->11 km/h. UV Index 4.
Wednesday
 
Clear throughout the day. Chance of precipitation (rain) 10%. High: 21°C. Low: 7°C. Wind WSW 4->10 km/h. UV Index 6.
Thursday
 
Clear throughout the day. High: 23°C. Low: 10°C. Wind WSW 4->12 km/h. UV Index 7.
Friday
 
Clear throughout the day. High: 24°C. Low: 9°C. Wind WSW 4->11 km/h. UV Index 7.
Saturday
 
Clear throughout the day. High: 25°C. Low: 8°C. Wind WNW 5->12 km/h. UV Index 7.

Hourly Forecast

09:00
Saturday


Mostly Cloudy
Mostly Cloudy
10:00
Saturday


Mostly Cloudy
Mostly Cloudy
11:00
Saturday


Possible Drizzle
Possible Drizzle
12:00
Saturday


Possible Drizzle
Possible Drizzle
13:00
Saturday


Possible Drizzle
Possible Drizzle
14:00
Saturday


Possible Light Rain
Possible Light Rain
15:00
Saturday


Possible Light Rain
Possible Light Rain
16:00
Saturday


Possible Light Rain
Possible Light Rain
8°C 10°C 12°C 13°C 14°C 13°C 13°C 13°C
UV: 1UV: 2UV: 3UV: 4UV: 4UV: 3UV: 3UV: 2
Wind S 6->10 km/h Wind S 7->12 km/h Wind S 7->14 km/h Wind S 10->20 km/h Wind S 11->25 km/h Wind S 13->29 km/h Wind SSW 13->31 km/h Wind SSW 13->31 km/h
rain rain rain rain rain rain rain rain

17:00
Saturday


Possible Drizzle
Possible Drizzle
18:00
Saturday


Possible Drizzle
Possible Drizzle
19:00
Saturday


Possible Drizzle
Possible Drizzle
20:00
Saturday


Possible Drizzle
Possible Drizzle
21:00
Saturday


Possible Drizzle
Possible Drizzle
22:00
Saturday


Possible Drizzle
Possible Drizzle
23:00
Saturday


Possible Drizzle
Possible Drizzle
00:00
Sunday


Possible Drizzle
Possible Drizzle
13°C 13°C 12°C 11°C 11°C 11°C 10°C 10°C
UV: 1UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0
Wind SSW 11->28 km/h Wind SSW 10->23 km/h Wind SSW 9->25 km/h Wind S 8->23 km/h Wind S 8->20 km/h Wind SSW 8->19 km/h Wind SSW 8->19 km/h Wind S 8->21 km/h
rain rain rain rain rain rain rain rain

01:00
Sunday


Possible Drizzle
Possible Drizzle
02:00
Sunday


Possible Drizzle
Possible Drizzle
03:00
Sunday


Possible Drizzle
Possible Drizzle
04:00
Sunday


Possible Drizzle
Possible Drizzle
05:00
Sunday


Possible Drizzle
Possible Drizzle
06:00
Sunday


Possible Drizzle
Possible Drizzle
07:00
Sunday


Possible Drizzle
Possible Drizzle
08:00
Sunday


Possible Drizzle
Possible Drizzle
10°C 9°C 9°C 9°C 9°C 9°C 9°C 9°C
UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0
Wind S 9->22 km/h Wind S 9->24 km/h Wind S 10->28 km/h Wind S 11->33 km/h Wind S 12->37 km/h Wind S 14->39 km/h Wind S 15->39 km/h Wind S 16->40 km/h
rain rain rain rain rain rain rain rain

09:00
Sunday


Light Rain
Light Rain
10:00
Sunday


Light Rain
Light Rain
11:00
Sunday


Light Rain
Light Rain
12:00
Sunday


Light Rain
Light Rain
13:00
Sunday


Light Rain
Light Rain
14:00
Sunday


Light Rain
Light Rain
15:00
Sunday


Light Rain
Light Rain
16:00
Sunday


Possible Light Rain
Possible Light Rain
10°C 10°C 11°C 11°C 11°C 11°C 11°C 11°C
UV: 1UV: 2UV: 2UV: 3UV: 3UV: 3UV: 3UV: 2
Wind SSW 18->40 km/h Wind SSW 18->41 km/h Wind SSW 19->41 km/h Wind S 17->40 km/h Wind SW 16->37 km/h Wind SW 15->34 km/h Wind SW 14->31 km/h Wind SSW 13->26 km/h
rain rain rain rain rain rain rain rain

 

Saratoga, CA, USA forecast by DarkSky.net.
Powered by Dark Sky
Sources for this forecast: NWSPA , CMC , GFS , HRRR , ICON , ISD , MADIS , NAM , SREF , DARKSKY

You can also include it 'silently' and print just a few (or all) the contents where you'd like it on the page

<?php
$doPrintDS = false;
require("DS-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>$DSforecasticons[0]</td><td>$DSforecasticons[1]</td>\n"; ?>
</tr>
<tr align="center" valign="top">
<?php print "<td>$DSforecasttemp[0]</td><td>$DSforecasttemp[1]</td>\n"; ?>
</tr>
</table>
Saturday
Light rain starting in the afternoon
Light rain starting in the afternoon
Sunday
Light rain throughout the day
Light rain throughout the day
14°C
9°C
11°C
4°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\">$DSforecasticons[0]<br />$DSforecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$DSforecasttext[0]</td>\n"; ?>
</tr>
<tr valign="top">
<?php print "<td align=\"center\">$DSforecasticons[1]<br />$DSforecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$DSforecasttext[1]</td>\n"; ?>
</tr>
</table>

Saturday
Light rain starting in the afternoon
Light rain starting in the afternoon
14°C
9°C
Light rain starting in the afternoon. Chance of precipitation (rain) 80%. High: 14°C. Low: 9°C. Wind SSW 8->31 km/h. UV Index 4.
Sunday
Light rain throughout the day
Light rain throughout the day
11°C
4°C
Light rain throughout the day. Chance of precipitation (rain) 100%. High: 11°C. Low: 4°C. Wind SSW 12->41 km/h. UV Index 3.

If you'd like to style the output, you can easily do so by setting a CSS for class DSforecast either in your CSS file or on the page including the DS-forecast.php (in include mode):

<style type="text/css">  
.DSforecast {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9pt;
}
</style>

Note: as of DS-forecast.php V1.09, pages that include() the DS-forecast.php script must have an added CSS in the <head>...</.head> part of the page. You can download the needed CSS from here. Either include that inline in the calling page, or add it to the existing CSS for your page.

Installation of DS-forecast.php

Download DS-forecast.php and DS-forecast-lang.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 DS-forecast.php for the $DSforecast address(s) and the address of the icons if necessary and upload the modified DS-forecast.php to your website.

Ensure the permission on "DS-forecast.txt" cache file are at least 666 or 766 so the file is writable by the DS-forecst.php script

Demo: DS-forecast-demo.php (note: uses UTF-8 only mode)
Download: DS-forecast.php (Version 1.09 - 23-Jan-2019)
Download: DS-forecast-lang.php (Version 1.06 - 23-Jan-2019)

If Standalone and running in a custom page:
Download: DS-forecast.css (Version 1.00 - 24-Jan-2019)

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

Version history

  • Version 1.09 - 23-Jan-2019 added hourly forecast and tabbed display (DS-forecast-lang.php V1.06 required)
  • Version 1.08 - 15-Jan-2019 added check for good JSON return before saving cache file
  • Version 1.07 - 10-Jan-2019 DS-forecast-lang.php V1.05 updated with missing Danish translation for 'snow'
  • Version 1.07 - 07-Jan-2019 fixed minor formatting issue with Hebrew in Saratoga template
  • Version 1.06 - 05-Jan-2019 fixed Hebrew language display when used in Saratoga template
  • Version 1.05 - 08-Dec-2018 added optional current conditions display box, cloud-cover now used for better icon choices
  • Version 1.04 - 04-Dec-2018 added lang=sr (Serbian) translation
  • Version 1.03 - 29-Nov-2018 added fixes for summaries with embedded UTF symbols.
  • Version 1.02 - 19-Nov-2018 added Updated: and DarkSky forecast by: display/translations
  • Version 1.01 - 17-Nov-2018 added wind unit translations, fixed -0C display, added alerts display (only English alerts are available), added sources links display
  • Version 1.00 - 16-Nov-2018 initial release

 

deformed-offering