DarkSky forecast script - multilingual for standalone/Saratoga templates

Given that WeatherUnderground has announced shutoff of the WU API on 31-Dec-2018, I thought it prudent to locate another source for forecasts that still offers free (low volume) access, is multilingual, and international coverage. DarkSky.net fits that with some caveats:

  1. forecasts are for 8 days (including today) and day-only forecasts are available (no night-time specific forecasts), but high/low expected temperatures are included for each day.

  2. The DarkSky text forecast is quite terse (more like an icon description), so the script ‘fleshes out’ the text forecast a bit by adding High/Low temperatures, Chance of Precipitation (if>0%), Wind direction, speed->gust, and UV index to the text.
    Because of the latter additions, for internationalization there is a required DS-forecast-lang.php which includes a encoded lookup array for day names+some weather terms in each supported language. All languages supported in the current Saratoga templates are covered (af,bg,cs,ct,de,dk,el,en,es,fi,fr,he,hu,it,nl,no,pl,pt,ro,se,si,sk).

The DS-forecast.php script is for standalone or Saratoga-template usage, and can output the text in either UTF-8 or the ISO-8859-n languages used in the Saratoga templates.

I’ll be doing some work to replace WU-forecast.php with DS-forecast.php in the Base-World template set soon.

You’ll find the docs/downloads/demo at the scripts page https://saratoga-weather.org/scripts-DSforecast.php
and a Demo page at https://saratoga-weather.org/DS-forecast-demo.php

Enjoy!

Hi,

There is a problem with line:

Warning: Division by zero in DS-forecast.php on line 634
and the line has such a command:
$wdth = intval(100/count($DSforecasticons));
Any idea why ?

Krzysztof

You are running on a very old PHP (PHP 5.2.17) and that version had issues with the json_decode() built-in function – The script needs PHP 5.3+ (preferably PHP 5.6 or 7.2).

You can try to get the script working by changing DS-forecast.php from

if(json_last_error() === JSON_ERROR_NONE) { // got good JSON .. process it
   $UnSupported = false;

to

if(isset($JSON['daily']['data'][0]['time'])) { // got good JSON .. process it
   $UnSupported = false;

and see if that gets it working.

I was not aware my provider did not upgrade PHP, anyway the change you suggested helped, and works fine now.
Thanx very much
Krzysztof

I’ve done an update to the DarkSky scripts today (8-Dec-2018) DS-forecast.php V1.05, DS-forecast-lang.php V1.04 that has the following additions:

  1. a new current-conditions block can now be displayed (default is to display it). DarkSky JSON has a current entry with conditions from a nearby station generally available. The Icon, conditions, sunrise/set, distance from forecast point and overall summary are displayed in the block. This is similar to the display with the ec-forecast.php script for Canadian forecasts.

  2. if precipitation is forecast, the type of precip (rain, snow, sleet) also appears in the text forecast like the ‘Chance of precipitation (rain) nn%’.

  3. since DarkSky has a very limited set of icons specified (currently limited to clear-day, clear-night, rain, snow, sleet, wind, fog, cloudy, partly-cloudy-day, or partly-cloudy-night), I’ve added a routine to use the cloud-coverage (converted to octets) to change the clear-, partly-cloudy- specs to use SKC, FEW, SCT, BKN, OVC icons as appropriate. Also, for wind icon, the same cloud-coverage is applied.
    Even with these changes, DarkSky continues to use -night icons when talking about full-day forecasts sometimes.

Update is available from the scripts page (update both scripts) and the Template update tool page ( query for 08-Dec-2018, Base-World, *-plugin)