Author Topic: New OpenWeatherMap and VisualCrossing weather forecast scripts available  (Read 2067 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
It's been a busy late Jan/early Feb with coding to add two more sources for international, multilingual forecasts:

OpenWeatherMap (https://openweathermap.org) and VisualCrossing (https://visualcrossing.com).  Both provide limited-use free API keys available.

Both providers only give one daily icon per-day for their forecasts, (so no day/night displays).
OpenWeatherMap does provide full translations for forecast text.
VisualCrossing provides de (German), en (English), es (Spanish), fi (Finnish), fr (French), it (Italian), pt (Portuguese), ru (Russian), nl (Netherlands), sr (Serbian). Other languages will return in English.

The OpenWeatherMap script page is here and on GitHub here.
The VisualCrossing script page is here and on GitHub here.

The scripts are included in the Base-World template using the update tool with query Base-World,*.Plugin, 07-Feb-2023

Note that Base-* templates also get updated ajax-dashboard.php V1.33, wxforecast.php V1.06 and check-fetch-times.php V1.49 to support the new scripts.

For a DarkSky replacement, I'd suggest using the OpenWeatherMap one as it has the most complete translations for multilingual use.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Lee10

  • Member
  • *
  • Posts: 20
This is a fantastic script and thanks for all the hard work.

However, I have problems using it as a stand-alone script. When I put in my API key in it comes out up as error and the forecast becomes invalid.

"Sorry.. the DarkSky forecast is not available" is what I get.

Regards

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Which script are you using?  What is the URL to the configured script on your website?
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Lee10

  • Member
  • *
  • Posts: 20
Thanks for your reply. I am using the OWM one and the URL is:

http://lee10.hyperphp.com/OWM-forecast.php

it says Dark Sky but I am using the OWM API key

Regards

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Doing a view-source: on your OWM-forecast.php page shows
Quote
<!-- OWM-forecast.php (ML) Version 2.01 - 07-Feb-2023 on PHP 7.4.8 -->
<!-- temps in C -->
<!-- loading from https://api.openweathermap.org/data/3.0/onecall?lat=37.27465&lon=-122.02295&exclude=minutely&units=metric&lang=en&appid={redacted}. -->
<!-- curl fetching 'https://api.openweathermap.org/data/3.0/onecall?lat=37.27465&lon=-122.02295&exclude=minutely&units=metric&lang=en&appid={redacted}' -->
<!-- HTTP stats:  RC=401 dest=82.196.7.246 port=443 (from sce=185.27.134.63)
      Times: dns=0.002 conn=0.017 pxfer=0.066 get=0.017 total=0.084 secs -->
<!-- headers:
HTTP/1.1 401 Unauthorized
Server: openresty
Date: Mon, 06 Mar 2023 16:31:47 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 338
Connection: keep-alive
X-Cache-Key: /data/3.0/onecall?exclude=minutely&lang=en&lat=37.27&lon=-122.02&units=metric
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
 -->
<!-- RC=401 Unauthorized, bytes=720 -->
<!-- bad return from https://api.openweathermap.org/data/3.0/onecall?lat=37.27465&lon=-122.02295&exclude=minutely&units=metric&lang=en&appid={redacted}
HTTP/1.1 401 Unauthorized
Server: openresty
Date: Mon, 06 Mar 2023 16:31:47 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 338
Connection: keep-alive
X-Cache-Key: /data/3.0/onecall?exclude=minutely&lang=en&lat=37.27&lon=-122.02&units=metric
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST

{"cod":401, "message": "Please note that using One Call 3.0 requires a separate subscription to the One Call by Call plan. Learn more here https://openweathermap.org/price. If you have a valid subscription to the One Call by Call plan, but still receive this error, then please see https://openweathermap.org/faq#error401 for more info."}
 -->
<!-- cache ./OWM-forecast-json-0-metric-en.txt missing or contains invalid contents -->
<p>Sorry.. the DarkSky forecast is not available.</p>
The 'DarkSky' should read 'OpenWeatherMap' .. sorry about that.

The JSON returned indicates that your key is valid, but you have not subscribed to the One Call by Call plan for your key.  Do the subscription, and the API should return data for the forecast.

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
I've released an update to OWM-forecast.php V2.02 to show the error message clearly when a non-successful API query happens.

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Lee10

  • Member
  • *
  • Posts: 20
Thanks for your reply. Did not notice about the One by One subscription I was on the free key.

Offline PeeGee

  • Member
  • *
  • Posts: 5
Good afternoon,

Thanks Ken for the new VC forecast script!  :grin:

But I have a question:

How or where can I change some words of the Dutch text in the VC-forecast-lang.php file  :?:

When I decode the trantable code using the online tool https://www.base64encode.org/ and then encode it again and replace the new trantable code in the VC-forecast-lang.php file I get the following error:

Notice: unserialize(): Error at offset 53 of 40756 bytes in /data/sites/web/leudalweernl/www/VC-forecast.php on line 2185.
This can be seen on the wxvcforekast.php page and the text is partly in English and Dutch.

Thanks in advance for a solution!

Regards,
PeeGee.
« Last Edit: August 05, 2023, 12:27:53 PM by PeeGee »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Ahhh.. it's a bit more complicated (as you discovered).
The translation table is a base64 encoded of a PHP serialized array.  You can't change the serialized array directly (as it as embedded length values).

You can see the unserialized version by using https://saratoga-weather.org/VC-forecast-lang.php?sce=dump and it shows the full set of language entries.

The array has to be serialized, then base64 encoded using something like
Code: [Select]
$transSerial = serialize($transArray);
$b64 = base64_encode($transSerial);
$outString = "\n";
$tArr = str_split($b64,72);
$outString .= "#\n";
$outString .= "define('TRANTABLE',\n'";
$tStr = '';
foreach($tArr as $rec) {
$tStr .= $rec."\n";
}
$tStr = trim($tStr);
$outString .= $tStr;
$outString .= "'); // end of TRANTABLE encoded\n";
print $outString;

Keep in mind that the translation table does not change any of the forecast text from visual crossing .. it only specifies the basic translations listed here
Code: [Select]
'nl' => array (
    'charset' => 'ISO-8859-1',
    'Today' => 'Vandaag',
    'High:' => 'Max:',
    'Low:' => 'Min:',
    'Wind' => 'Wind',
    'Chance of precipitation' => 'Kans op neerslag',
    'Temperature' => 'Temperatuur',
    'Barometer' => 'Barometer',
    'Dew Point' => 'Dauwpunt',
    'Humidity' => 'Vochtigheid',
    'Sunrise' => 'Zonsopgang',
    'Sunset' => 'Zonsondergang',
    'Currently' => 'Huidige',
    'Sunday' => 'Zondag',
    'Monday' => 'Maandag',
    'Tuesday' => 'Dinsdag',
    'Wednesday' => 'Woensdag',
    'Thursday' => 'Donderdag',
    'Friday' => 'Vrijdag',
    'Saturday' => 'Zaterdag',
    'Sunday night' => 'Zondag nacht',
    'Monday night' => 'Maandag nacht',
    'Tuesday night' => 'Dinsdag nacht',
    'Wednesday night' => 'Woensdag nacht',
    'Thursday night' => 'Donderdag nacht',
    'Friday night' => 'Vrijdag nacht',
    'Saturday night' => 'Zaterdag nacht',
    'Tonight' => 'Vannacht',
    'This afternoon' => 'Vanmiddag',
    'Rest of tonight' => 'Middernacht',
    'Updated:' => 'laatste update:',
    'Visualcrossing Forecast for:' => 'Visualcrossing weersverwachting voor:',
    'NESW' => 'NOZW',
    'kph' => 'km/u',
    'rain' => 'regen',
    'sleet' => 'natte sneeuw',
    'Visibility' => 'Zicht',
    'Wind chill' => 'Gevoelstemperatuur',
    'Heat index' => 'Hitte index',
    'Meteogram' => 'Meteogram',
    'UV index' => 'UV-index',
    'mph' => 'mph',
    'mps' => 'm/s',
    'snow' => 'sneeuw',
    'Humidex' => 'humidex',
    'Weather conditions at 999 from forecast point.' => 'Weersomstandigheden op 999 vanaf voorspellings punt.',
    'Daily Forecast' => 'Dagelijkse voorspelling',
    'Hourly Forecast' => 'Uurlijkse voorspeling',
  ), // end nl

So, what is it you wanted the change in the Dutch translation?
« Last Edit: August 05, 2023, 03:02:58 PM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline PeeGee

  • Member
  • *
  • Posts: 5
Thanks for your explanation Ken, learned something new. So it's not as easy as I thought.
What matters are indeed words of the basic translation, which I would like to translate into better Dutch for me.
Would like to do it myself if I knew how to do it so will have to follow some more tutorials. :-) 

I would like the following words/phrases to be better translated if possible.

Code: [Select]
'nl' => array (
    'charset' => 'ISO-8859-1',

    'Sunrise' => 'Zonsopgang', into 'Sunrise' => 'Zonsopkomst',
    'Currently' => 'Huidige', into 'Currently' => 'Actueel op',
    'Updated:' => 'laatste update:', into 'Updated:' => 'Laatste update:',
    'Weather conditions at 999 from forecast point.' => 'Weersomstandigheden op 999 vanaf voorspellings punt.', into 'Weather conditions at 999 from forecast point.' =>  'Weersomstandigheden op 999 vanaf het waarnemings punt.',
    'Daily Forecast' => 'Dagelijkse voorspelling', into 'Daily Forecast' => 'Verwachting per dag',
    'Hourly Forecast' => 'Uurlijkse voorspeling', for the original to (because missing one l)  'Hourly Forecast' => 'Uurlijkse voorspelling',
     For me into
    'Hourly Forecast' => 'Verwachting per uur',
 
   ), // end nl


Thanks in advance for doing this!

Regards,
PeeGee.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: New OpenWeatherMap and VisualCrossing weather forecast scripts available
« Reply #10 on: August 06, 2023, 03:44:19 PM »
Got the Dutch (NL) translation updated with your suggestions.

Download from https://saratoga-weather.org/VC-forecast-lang.php?sce=view or use the template update tool with a query of Base-World, Plugin-*, 06-Aug-2023

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline PeeGee

  • Member
  • *
  • Posts: 5
Re: New OpenWeatherMap and VisualCrossing weather forecast scripts available
« Reply #11 on: August 07, 2023, 07:03:37 AM »
Thank you it works fine for me. Bought you a nice cappuccino. Is it correct that the Trantable can also be used for the PW and OWM forecast?
Greetings from the Netherlands.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: New OpenWeatherMap and VisualCrossing weather forecast scripts available
« Reply #12 on: August 07, 2023, 10:27:31 AM »
Thanks for the cappuccino!  The translation tables for PW and OWM are related, but not identical.  I'll have to regenerate them with the Dutch updates.
I'd used the translations created for the templates, WXSIM forecast and a bit of Google Translate to create the master copies.. it was likely the Google Translate entries you'd changed with better content.

I'll post those updates later today.

Edit: OWM and PW translation files now available via template update tool, github or the script pages.
« Last Edit: August 07, 2023, 11:24:28 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP