Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Simple way to add remote data to the Cumulus website

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
fractonimbus
Posts: 159
Joined: Thu 03 Feb 2011 1:15 am
Weather Station: WH1091
Operating System: Windows 7 on a Dell Vostro
Location: Canberra

Simple way to add remote data to the Cumulus website

Post by fractonimbus »

In case anyone is interested...

For no essential reason I wanted to add the Southern Oscillation Index (NINO 3.4) and Indian Ocean Dipole index (updated weekly) to my main weather page (http://www.dcnicholls.com/wx). The data are available as time series on the Australian Bureau of Meteorology site. So the idea was simply to read the data pages, chop out the latest index values, and insert them into my web page. Sounded easy but it wasn't as it turns out to be quite difficult (impossible?) to use something like Javascript to access cross domain pages.

I finished up using PHP to read the data and "echo" it, and the jQuey Ajax routines to call the PHP and accept the output into a form that I could use Javascript to add to the page.

The PHP code is:

Code: Select all

<?php
header('Content-type: text/plain');   //probably unnecessary
$soi34 = file_get_contents('http://www.bom.gov.au/climate/enso/nino_3.4.txt');
if (soi34) { $soix = substr($soi34,-6); }  // the data I want is the final 5 characters
else { $soix = "n/a"; }
$iod= file_get_contents('http://www.bom.gov.au/climate/enso/iod_1.txt');
if ($iod) { $iodx = substr($iod,-6); }
else { $iodx = "n/a"; }
echo "$soix,$iodx";
?>
and the jQuery code, added to daj's js file (called wc2.js in my version of it), is:

Code: Select all

var bomproxy="/wx/p.php";
var bomdata = $.ajax({url: bomproxy, async: false, dataType: "text" }).responseText;
var rawbomdata=bomdata.split(',');
var soi = rawbomdata[0];
var iod = rawbomdata[1];
which is then "document.write" processed in the index.htm web page.

There are probably better ways to do this but I'm a neophyte js, Ajax and PHP programmer :-|

The BOM stuff is available via http://www.bom.gov.au/climate/IOD/about_IOD.shtml

DN
Image
fractonimbus
Posts: 159
Joined: Thu 03 Feb 2011 1:15 am
Weather Station: WH1091
Operating System: Windows 7 on a Dell Vostro
Location: Canberra

Re: Simple way to add remote data to the Cumulus website

Post by fractonimbus »

Whoops - the PHP only worked provided there were 5 characters - drop the minus sign and it breaks.

So this is now the revised code - using Regex to strip all but the last number and its sign after the last comma in the downloaded csv files:

Code: Select all

<?php
$pat = '#[\s\S]*,(.*)#';
$rep = '$1';
header('Content-type: text/plain');
$soi34 = file_get_contents('http://www.bom.gov.au/climate/enso/nino_3.4.txt');
if ($soi34) { $soix = preg_replace($pat, $rep, $soi34); }
else { $soix = "n/a"; }

$iod= file_get_contents('http://www.bom.gov.au/climate/enso/iod_1.txt');
if ($iod) { $iodx = preg_replace($pat, $rep, $iod); }
else { $iodx = "n/a"; }
echo "$soix,$iodx";
?>
DN
Post Reply