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

Buy Me A Coffee 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.

Note: Twitter widget has been disabled 3-Jul-2023 since it no longer displays the recent update Tweets.

This page was updated Monday, 07-Aug-2023 8:15 AM

OpenWeatherMap International forecast formatting script - multilingual

This script was designed to replace the DS-forecast.php script as Apple purchased DarkSky and is only offering legacy API access for a limited time.
Fortunately, there is an API that mimics the DarkSky API provided by openweathermap.org.

Note that the OpenWeatherMap API only provides Daily forecasts, so no night-time forecast icons are available. Full multi-linguagal forecasts are available.
The OWM-forecast-lang.php provides translation capabilities for Saratoga Template languages for additional text added to the text forecast from data provided by OpenWeatherMap API (i.e. Temperature High/Low, Probibility of precipation, Wind direction, speed and gust, UV index ). The OWM-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

In order to use this script you need to:

  1. Register for and acquire a free OpenWeatherMap API key.
    1. Browse to https://openweathermap.org and sign in to acquire an API key
    2. Using the OWM site, subscribe the API key to your account to activate it for API usage.
      You'll see a message like the following if you have not subscribed the API feed in your OpenWeatherMap account:
      OWM 401 Error message
    3. insert the API key in $OWMAPIkey in the OWM-forecast.php script or as $SITE['OWMAPIkey'] in Settings.php for Saratoga template users.
    4. Customize the $OWMforecasts array (or $SITE['OWMforecasts'] 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 OpenWeatherMap 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 OpenWeatherMap.

Settings in the OWM-forecast.php script

// Settings ---------------------------------------------------------------
// REQUIRED: a openweathermap.org API KEY.. sign up at https://www.openweathermap.org/api
$OWMAPIkey = '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['OWMAPIkey'] = '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/
//
// The forecast(s) .. make sure the first entry is the default forecast location.
// The contents will be replaced by $SITE['OWMforecasts'] if specified in your Settings.php

$OWMforecasts = array(
 // Location|lat,long  (separated by | characters)
'Saratoga, CA, USA|37.27465,-122.02295',
'Auckland, NZ|-36.910,174.771', // Awhitu, Waiuku New Zealand
'Assen, NL|53.02277,6.59037',
'Blankenburg, DE|51.8089941,10.9080649',
'Cheyenne, WY, USA|41.144259,-104.83497',
'Carcassonne, FR|43.2077801,2.2790407',
'Braniewo, PL|54.3793635,19.7853585',
'Omaha, NE, USA|41.19043,-96.13114',
'Johanngeorgenstadt, DE|50.439339,12.706085',
'Athens, GR|37.97830,23.715363',
'Haifa, IL|32.7996029,34.9467358',
); 

//
$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 = 8;                 // 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 = "OWM-forecast-json.txt";      // locally cached page from OWM
$refetchSeconds = 3600;                   // cache lifetime (3600sec = 60 minutes)
//
// Units: Temp,Baro,Wind,Rain,Snow,Distance
// 'si' = C,hPa,m/s,mm,mm,km
// 'ca' = C,hPa,km/h,mm,mm,km
// 'uk' = C,mb,mph,mm,mm,km
// 'us' = F,inHg,mph,in,in,km
// 
$showUnitsAs  = 'ca'; //

$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
$timeFormat = 'Y-m-d H:i T';  // default time display format

$showConditions = true; // set to true to show current conditions box

// ---- 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 OWM-forecast.php on your site when new versions are released.
You DO have to add a $SITE['OWMAPIkey'] = 'your-key-here'; and a $SITE['OWMforecasts] = array( ...); entries to your Settings.php file to support this and future releases of the script.

$OWMAPIkey = 'specify-for-standalone-use-here';
This setting is for standalone use (do not change this for Saratoga templates).
Register for a OpenWeatherMap API Key at https://openweathermap.org/ 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 OpenWeatherMap API site above, then put your API key in your Settings.php as:

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

to allow easy future updates of the OWM-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.
 
$OWMforecasts = 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['OWMforecasts'] = 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 OpenWeatherMap. 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
='uk' 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,km)
Saratoga template users: This setting will be overridden by the $SITE['OWMshowUnitsAs'] 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
$doIncludeOWM = true;
include("OWM-forecast.php"); ?>

 

OpenWeatherMap Forecast for: - Saratoga, CA, USA

Currently: Fri, 13-Dec-2024 11:18am PST
overcast clouds
overcast clouds
Temperature: 13°C
Wind: SE 24 km/h.
Humidity: 81%
Dew Point: 9°C
Barometer: 1022.0 hPa
Visibility: 10 km
UV Index: 1
Sunrise: 07:14
Sunset: 16:51
OpenWeatherMap Forecast for: Saratoga, CA, USA
Updated:Fri, 13-Dec-2024 11:00am PST

 

Daily Forecast

Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday
moderate rain heavy intensity rain clear sky light rain broken clouds clear sky overcast clouds clear sky
moderate rain heavy intensity rain clear sky light rain broken clouds clear sky overcast clouds clear sky
13°C
10°C
13°C
7°C
13°C
6°C
16°C
7°C
15°C
8°C
17°C
8°C
20°C
10°C
21°C
11°C

Wind Advisory


Friday
 
moderate rain. Chance of precipitation 100% (rain 2.1mm). High: 13°C. Low: 10°C. Wind S 32->65 km/h. UV Index 2.
Saturday
 
heavy intensity rain. Chance of precipitation 100% (rain 41.2mm). High: 13°C. Low: 7°C. Wind SSW 32->74 km/h. UV Index 2.
Sunday
 
clear sky. High: 13°C. Low: 6°C. Wind NNE 6->7 km/h. UV Index 2.
Monday
 
light rain. Chance of precipitation 40% (rain 0.3mm). High: 16°C. Low: 7°C. Wind SSW 6->7 km/h.
Tuesday
 
broken clouds. High: 15°C. Low: 8°C. Wind N 10->17 km/h. UV Index 2.
Wednesday
 
clear sky. High: 17°C. Low: 8°C. Wind NNE 5->6 km/h. UV Index 3.
Thursday
 
overcast clouds. High: 20°C. Low: 10°C. Wind NE 4->4 km/h. UV Index 3.
Friday
 
clear sky. High: 21°C. Low: 11°C. Wind SW 8->13 km/h. UV Index 3.

Hourly Forecast

11:00
Friday


overcast clouds
overcast clouds
12:00
Friday


overcast clouds
overcast clouds
13:00
Friday


overcast clouds
overcast clouds
14:00
Friday


overcast clouds
overcast clouds
15:00
Friday


overcast clouds
overcast clouds
16:00
Friday


overcast clouds
overcast clouds
17:00
Friday


overcast clouds
overcast clouds
18:00
Friday


overcast clouds
overcast clouds
13°C13°C13°C13°C12°C12°C12°C12°C
UV: 1.45UV: 1.94UV: 1.25UV: 0.71UV: 0.14UV: 0.05UV: 0UV: 0
Wind S 12->21 km/h Wind S 11->23 km/h Wind S 12->25 km/h Wind S 12->27 km/h Wind S 12->33 km/h Wind S 11->35 km/h Wind S 10->26 km/h Wind S 11->37 km/h

19:00
Friday


overcast clouds
overcast clouds
20:00
Friday


overcast clouds
overcast clouds
21:00
Friday


overcast clouds
overcast clouds
22:00
Friday


overcast clouds
overcast clouds
23:00
Friday


moderate rain
moderate rain
00:00
Saturday


moderate rain
moderate rain
01:00
Saturday


heavy intensity rain
heavy intensity rain
02:00
Saturday


moderate rain
moderate rain
12°C11°C11°C12°C12°C12°C11°C11°C
UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0
Wind S 12->32 km/h Wind S 12->31 km/h Wind S 14->46 km/h Wind S 24->54 km/h Wind S 32->65 km/h Wind S 22->53 km/h Wind SSE 20->55 km/h Wind SSE 19->54 km/h
rain: 1.2mm rain: 3.7mm rain: 5.7mm rain: 1.2mm

03:00
Saturday


overcast clouds
overcast clouds
04:00
Saturday


light rain
light rain
05:00
Saturday


light rain
light rain
06:00
Saturday


moderate rain
moderate rain
07:00
Saturday


heavy intensity rain
heavy intensity rain
08:00
Saturday


heavy intensity rain
heavy intensity rain
09:00
Saturday


light rain
light rain
10:00
Saturday


light rain
light rain
11°C11°C11°C11°C11°C13°C12°C12°C
UV: 0UV: 0UV: 0UV: 0UV: 0UV: 0.01UV: 0.26UV: 0.4
Wind SSE 19->54 km/h Wind SSE 21->57 km/h Wind SSE 21->56 km/h Wind SSE 25->74 km/h Wind SSE 20->66 km/h Wind S 31->70 km/h Wind SSW 32->58 km/h Wind SW 23->46 km/h
rain: 0.2mm rain: 0.3mm rain: 3.4mm rain: 13.2mm rain: 11.7mm rain: 0.6mm rain: 0.1mm

11:00
Saturday


light rain
light rain
12:00
Saturday


light rain
light rain
13:00
Saturday


light rain
light rain
14:00
Saturday


broken clouds
broken clouds
15:00
Saturday


broken clouds
broken clouds
16:00
Saturday


overcast clouds
overcast clouds
17:00
Saturday


overcast clouds
overcast clouds
18:00
Saturday


overcast clouds
overcast clouds
11°C12°C11°C12°C12°C11°C9°C9°C
UV: 0.88UV: 1.95UV: 1.8UV: 1.26UV: 0.57UV: 0.14UV: 0UV: 0
Wind W 21->53 km/h Wind W 19->42 km/h Wind W 17->36 km/h Wind W 14->28 km/h Wind W 11->27 km/h Wind W 7->20 km/h Wind W 3->3 km/h Wind E 2->2 km/h
rain: 0.1mm rain: 0.3mm rain: 0.7mm

 

Saratoga, CA, USA forecast by openweathermap.org.

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

<?php
$doPrintOWM = false;
require("OWM-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>$OWMforecasticons[0]</td><td>$OWMforecasticons[1]</td>\n"; ?>
</tr>
<tr align="center" valign="top">
<?php print "<td>$OWMforecasttemp[0]</td><td>$OWMforecasttemp[1]</td>\n"; ?>
</tr>
</table>
Friday
moderate rain
moderate rain
Saturday
heavy intensity rain
heavy intensity rain
13°C
10°C
13°C
7°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\">$OWMforecasticons[0]<br />$OWMforecasttemp[0]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$OWMforecasttext[0]</td>\n"; ?>
</tr>
<tr valign="top">
<?php print "<td align=\"center\">$OWMforecasticons[1]<br />$OWMforecasttemp[1]</td>\n"; ?>
<?php print "<td align=\"left\" valign=\"middle\">$OWMforecasttext[1]</td>\n"; ?>
</tr>
</table>

Friday
moderate rain
moderate rain
13°C
10°C
moderate rain. Chance of precipitation 100% (rain 2.1mm). High: 13°C. Low: 10°C. Wind S 32->65 km/h. UV Index 2.
Saturday
heavy intensity rain
heavy intensity rain
13°C
7°C
heavy intensity rain. Chance of precipitation 100% (rain 41.2mm). High: 13°C. Low: 7°C. Wind SSW 32->74 km/h. UV Index 2.

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

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

Installation of OWM-forecast.php

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

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

Demo: OWM-forecast-demo.php (note: uses UTF-8 only mode)
Download: OWM-forecast.php (Version 2.02 - 06-Mar-2023)
Download: OWM-forecast-lang.php (Version 1.08 - 07-Aug-2023)

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

Version history

  • Version 2.02 - 06-Mar-2023 added diagnostics for 40x API failures
  • Version 2.01 - 07-Feb-2023 added units conversions and si,ca,uk,us for ShowUnitsAs compatibility
  • Version 2.00 - 04-Feb-2023 initial release

 

deformed-offering