cloudy cloudy

Author Topic: DarkSky forecast script - multilingual for standalone/Saratoga templates  (Read 345 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Global Moderator
  • Posts: 5,842
  • Ken True
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
  • OS/Browser:
  • Win NT 10.0
  • Firefox 63.0
    • Saratoga Weather
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!
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline kd3141

  • Posts: 85
  • Poland
  • OS/Browser:
  • Mac OS X 10.14.1
  • Chrome 70.0.3538.102
    • Meteo Fiolkowa
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #1 on: November 20, 2018, 10:39:56 AM »
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
Krzysiek

Offline saratogaWX

  • Global Moderator
  • Posts: 5,842
  • Ken True
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
  • OS/Browser:
  • Win NT 10.0
  • Firefox 63.0
    • Saratoga Weather
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #2 on: November 20, 2018, 03:07:28 PM »
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
Code: [Select]
if(json_last_error() === JSON_ERROR_NONE) { // got good JSON .. process it
   $UnSupported = false;
to
Code: [Select]
if(isset($JSON['daily']['data'][0]['time'])) { // got good JSON .. process it
   $UnSupported = false;
and see if that gets it working.
« Last Edit: November 20, 2018, 03:23:47 PM by saratogaWX »
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline kd3141

  • Posts: 85
  • Poland
  • OS/Browser:
  • Mac OS X 10.14.1
  • Chrome 70.0.3538.102
    • Meteo Fiolkowa
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #3 on: November 20, 2018, 08:17:55 PM »
I was not aware my provider did not upgrade PHP, anyway the change you suggested helped, and works fine now.
Thanx very much
Krzysztof
Krzysiek

Offline saratogaWX

  • Global Moderator
  • Posts: 5,842
  • Ken True
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
  • OS/Browser:
  • Win NT 10.0
  • Firefox 63.0
    • Saratoga Weather
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #4 on: December 08, 2018, 07:19:53 PM »
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)
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

 

cumulus