Display Inshore forecast from BOM for digital signage or website
Posted: Wed 10th April 2019 in Blog
Position: 12° 27.6' S, 130° 48.1' E
the Following code will go grab the xml for the Darwin Harbour inshore forecast from BOM and save it to disk as a htm and txt file.
The idea is run it once as a cron job - then just call the txt or htm file to display it for hte rest of the day
getElementsByTagName('forecast') as $e ) {
$e = $e->parentNode; // this should be the element
foreach( $e->getElementsByTagName('forecast-period') as $l ) {
if($l->getAttribute('index')=='0') {
$date = date( "l jS F ", strtotime($l->getAttribute('start-time-local')));
$curTxt= "Forcast for Darwin Harbour for $date \n \n";
$curHtm= "
\n";
}
}
}
}
//Dispaly as text
echo $curTxt;
file_put_contents('../../imagecache/forecast.txt', $curTxt); //save file for rest of the day.
//separator
echo "############################################################################## \n";
//display as html
$curHtm=$curHtm."
";
echo $curHtm;
file_put_contents('../../imagecache/forecast.htm', $curHtm); //save file for the resrt of hte day.
?>
\n";
}
}
}
}
//Dispaly as text
echo $curTxt;
file_put_contents('../../imagecache/forecast.txt', $curTxt); //save file for rest of the day.
//separator
echo "############################################################################## \n";
//display as html
$curHtm=$curHtm."
";
echo $curHtm;
file_put_contents('../../imagecache/forecast.htm', $curHtm); //save file for the resrt of hte day.
?>