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

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
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, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline sacreyweather

  • Echo Valley Weather
  • Forecaster
  • *****
  • Posts: 1648
    • Echo Valley Weather
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #1 on: November 18, 2018, 02:35:58 PM »
Hi Ken,

Thanks for the new forecast script. Wanted to let you know the signup URL you have returns a 404 for me. The one that I found that works was DarkSky API.


John
CWOP: D2073, GR2AE, GR3, Cumulus, PWSweather,  CoCoRaHS: AR-SL-23  

Saline Weather on Twitter
Blitzortung Station 1387

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #2 on: November 18, 2018, 03:30:36 PM »
Thanks John,
I'll change the docs..  I'd originally done the script in December 2017 but hadn't finished it.. added the finishing touches (like translations) and forgot to check the original doc url for signup.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline W Thomas

  • Welcome To Life In The High Country!
  • Forecaster
  • *****
  • Posts: 1542
  • In Loving Memory Of Hooker The Weather Dog !
    • Smyth Weather
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #3 on: November 26, 2018, 11:01:37 PM »
I have been experimenting with the Dark Sky forecast script as a likely replacement for my WU Specialized forecast.
I have a strange temperature display meaning it is displaying way colder temperatures than we are expecting. However I know it's colder than a well drillers auger here but I actually hope those temps are wrong  8-)

You can see what I am talking about here   http://www.smythweather.net/TestBed/DS-Forecast.php?z=0
I haven't gotten the icons working yet,they are uploaded but I've missed something there as well :grin:

I'm open for ideas on this little issue.  So far I really like the data from DarkSky and Ken's excellent coding work! Seems they page call volume is more than enough for me. I wish I had oodles of hits per day but alas I dont :lol:

Thanks in advance!


     Best Regards
     Wayne

CWOP CW8217
KVAWHITE22 Wunderground   Davis VUE &  Davis Vantage Pro 2  /   Dedicated Server
GR Level 3 ,Level 2 AE Radars  Weather Display 10.37P  Mid Atlantic Weather Network Member
SkyWarn & Spotter Network 6092

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #4 on: November 27, 2018, 10:40:24 AM »
For the images, you might try using
Code: [Select]
$iconDir ='../forecast/images/'; // directory for carterlake icons './TestBed/images/'
since you have the icons in your main directory.

Thanks for the kind words :)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline W Thomas

  • Welcome To Life In The High Country!
  • Forecaster
  • *****
  • Posts: 1542
  • In Loving Memory Of Hooker The Weather Dog !
    • Smyth Weather
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #5 on: November 27, 2018, 10:57:15 AM »
Thanks Ken!
Working great now!


     Best Regards
     Wayne

CWOP CW8217
KVAWHITE22 Wunderground   Davis VUE &  Davis Vantage Pro 2  /   Dedicated Server
GR Level 3 ,Level 2 AE Radars  Weather Display 10.37P  Mid Atlantic Weather Network Member
SkyWarn & Spotter Network 6092

Offline pimohdaimaoh

  • Senior Contributor
  • ****
  • Posts: 180
  • "Be aware to our nature"
    • PIMOHWEATHER
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #6 on: November 29, 2018, 06:00:32 AM »
Hello ken,

This is what im waiting Ken and good job creating it early so that we can ready/preparing of transfering our forecast script from WU, before WU is going to close on Dec 31 this year. I am now beginning to transfer its script from WU to DS, but I have a problem. since I change the WU-forecast.php into DS-forecast.php in settings why the DS-forecast.php also showing on my ajax dashboard? I didnt include this on ajax-dashboard? it should only view on wxDSforecast.php? (see image) how to remove this on ajax-dashboard which it should only view the variables on ajax-dashboard, instead?

Hope you can help me to fix it.

regardss;

Mike

My test Site:
http://pimohweather.webutu.com
My CWOP ID: EW0758

Offline chappelledpc

  • Contributor
  • ***
  • Posts: 117
    • Stonybrook South
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #7 on: November 29, 2018, 12:26:47 PM »
Hi Ken,

Thanks for making this available.  Have a question about the forecast text that shows up under the icons.

If you take a look at my example below, you see that the text after the snow amount for Sunday and Monday is getting truncated.  Does have something to do with the close parenthesis ) or possibly the period after in

Thanks,
Doug

 [ You are not allowed to view attachments ]
 
« Last Edit: November 29, 2018, 12:32:19 PM by chappelledpc »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #8 on: November 29, 2018, 12:28:47 PM »
Looks like you discovered that changing the Settings.php from
Code: [Select]
$SITE['fcstscript']    = 'WU-forecast.php';    // Non-USA, Non-Canada Wunderground Forecast Script
$SITE['fcstorg']        = 'WU';    // set to 'WU' for WeatherUnderground
to use DarkSky instead won't work correctly.  I have to issue some updates to Settings.php, ajax-dashboard.php, wxforecast.php to allow easy integration of DS-forecast.php into the Saratoga template.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #9 on: November 29, 2018, 12:33:07 PM »
I think it's a browser/HTML issue with their return.  The JSON says 'Light snow (< 1 in.) in the morning.'

I think I'll have to add a bit of processing to make that 'Light snow (&amp; 1 in.) in the morning.' so the browser's HTML parser won't be confused and thing there's an open tag starting.   :roll: #-o
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #10 on: November 29, 2018, 12:54:12 PM »
Try changing
Code: [Select]
$DSforecasttext[$n] = trim($FCpart['summary']); to
Code: [Select]
$DSforecasttext[$n] =
   str_replace(array('<','>','–','cm.','in.'),array('&lt;','&gt;','-','cm','in'),
   trim($FCpart['summary']));
That seems to get the correct stuff displayed.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline chappelledpc

  • Contributor
  • ***
  • Posts: 117
    • Stonybrook South
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #11 on: November 29, 2018, 03:48:12 PM »
Thanks Ken.  That did fix it  =D&gt;

One interesting note is the forecast did change from my last post, but the updated time didn't.  Looks like they are using midnight hour consistently in the daily array.  Maybe you can consider using $JSON['currently']['time'] rather than $JSON['daily']['data'][0]['time'] for the $DSupdated variable?  Just a thought.

Thanks,
Doug

 [ You are not allowed to view attachments ]

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #12 on: November 29, 2018, 03:53:52 PM »
Funny you should mention the update time.. I'd sent them an email suggesting both a "updated" JSON entry with the UTC timestamp for the forecast (it doesn't have that now), AND to consider offering Day/Night forecasts instead of just Full Day forecasts.
They said they would forward to the developers.

Meanwhile, the only date provided by them is midnight local time for the first period in the forecast.  Yes, they do update the forecasts multiple times per day, but the JSON doesn't have a field to represent that.  Using the current time would give a false impression of the actual forecast time IMHO..
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline chappelledpc

  • Contributor
  • ***
  • Posts: 117
    • Stonybrook South
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #13 on: November 29, 2018, 04:01:39 PM »
Funny you should mention the update time.. I'd sent them an email suggesting both a "updated" JSON entry with the UTC timestamp for the forecast (it doesn't have that now), AND to consider offering Day/Night forecasts instead of just Full Day forecasts.
They said they would forward to the developers.

Meanwhile, the only date provided by them is midnight local time for the first period in the forecast.  Yes, they do update the forecasts multiple times per day, but the JSON doesn't have a field to represent that.  Using the current time would give a false impression of the actual forecast time IMHO..

I agree that would give a false impression.  We'll see how open and responsive they are to suggestions.

Offline pimohdaimaoh

  • Senior Contributor
  • ****
  • Posts: 180
  • "Be aware to our nature"
    • PIMOHWEATHER
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #14 on: November 29, 2018, 05:54:15 PM »
Looks like you discovered that changing the Settings.php from
Code: [Select]
$SITE['fcstscript']    = 'WU-forecast.php';    // Non-USA, Non-Canada Wunderground Forecast Script
$SITE['fcstorg']        = 'WU';    // set to 'WU' for WeatherUnderground
to use DarkSky instead won't work correctly.  I have to issue some updates to Settings.php, ajax-dashboard.php, wxforecast.php to allow easy integration of DS-forecast.php into the Saratoga template.

Yes ken, when I change these to DS-forecasts.php, the wxforecast.php works fine, except the above I mentioned which the stand alone of DS-forecast.php also showing on the ajax-dashboard in which supposed not to. I hope you look on that issue soon. Thank You.

My test Site:
http://pimohweather.webutu.com
My CWOP ID: EW0758

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #15 on: November 29, 2018, 07:23:37 PM »
To use DarkSky forecast requires changes to ajax-dashboard.php, Settings.php, wxforecast.php scripts that I'm working on, but haven't released.  For now, just stick with WU-forecast.php as it is working for you.

There will be a future Base-World update to replace WU-forecast.php with DS-forecast.php with instructions on how to do that..
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #16 on: December 08, 2018, 02:18:59 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, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Toxic

  • Senior Contributor
  • ****
  • Posts: 277
  • #conligwx
    • conligwx.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #17 on: December 08, 2018, 06:01:43 PM »
Ken,

from the main dashboard view can I remove the wording under the icon at all and just leave the Icon and Max/Min Temps or is the Words and Icons linked together?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6874
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: DarkSky forecast script - multilingual for standalone/Saratoga templates
« Reply #18 on: December 08, 2018, 07:12:37 PM »
The data for DS-forecast.php is returned in:

 $DSforecastday[$i]   - period of forecast
 $DSforecasttext[$i]   - text of forecast
 $DSforecasttemp[$i]   - Temperature with text and formatting
 $DSforecastpop[$i]   - Number - Probabability of Precipitation ('',10,20, ... ,100)
 $DSforecasticon[$i]   - base name of icon graphic to use
 $DSforecastcond[$i]   - Short legend for forecast icon
 $DSforecasticons[$i]  - Full icon with Period, <img> and Short legend.
 $DSforecastwarnings = styled text with hotlinks to advisories/warnings
 $DScurrentConditions = table with current conds at point close to lat/long selected

The $DSforecasticons[$i] array has day-name,icon,text but not the temps.  The temps are in $DSforecasttemp[$i] as formatted text.

In ajax-dashboard.php  the compatibility code does stuff like
Code: [Select]
if ($fcstorg == 'DarkSky') {
  $forecasticons = $DSforecasticons;
  $forecasttemp = $DSforecasttemp;
  $forecasttitles = $DSforecasttitles;
  $forecasttext = $DSforecasttext;

}
so the dashboard can display the output in the 'Outlook' and Short term forecast areas (which use the $forecast* variable names.  The same kind of mapping is done for ec-forecast, WXSIM plaintext-parser, and WU-forecast scripts.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP