diff options
Diffstat (limited to 'synopticChart.sh')
| -rwxr-xr-x | synopticChart.sh | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/synopticChart.sh b/synopticChart.sh index e7d3726..a515c90 100755 --- a/synopticChart.sh +++ b/synopticChart.sh @@ -1,37 +1,49 @@ #!/bin/bash -# SJP 28 Nov 2021 -# Get synoptic weather charts from BOM and make them into a movie -# See notes about BOM. they don't like scrapers but permit anon FTP -# for *personal use* -# This script will be called froma timer, once every 6 hours, which is -# how often new charts are published. -# -# The timer will take care of scheduing the call to the script -# todo: check what happens with daylight saving... +set -euo pipefail -source func/deriveTimeString.sh +# SJP 28 Nov 2021 — extended for deployment +# Download BOM synoptic chart (IDY00030) and publish as PNG. +# BOM permits anonymous FTP for personal use. +# Charts are valid at 00, 06, 12, 18 UTC; files appear ~2h later. +# Deployed to /opt/synoptic/synopticChart.sh on pestrel.com. -dateTime=$(DeriveTime) +ARCHIVE_DIR=/var/lib/synoptic/archive +RAW_DIR=/var/lib/synoptic/archive/raw +LATEST=/srv/www/synopticLatest.png + +# Return the datetime string for the most recently published chart slot. +# BOM chart slots: 0000, 0600, 1200, 1800 UTC. +DeriveTime() { + local nowDate nowTime fileTime + nowDate=$(date -u +%Y%m%d) + nowTime=$(date -u +%H%M) + + if [ "$nowTime" -ge 1800 ]; then fileTime=1800 + elif [ "$nowTime" -ge 1200 ]; then fileTime=1200 + elif [ "$nowTime" -ge 0600 ]; then fileTime=0600 + else fileTime=0000 + fi -latestChart=IDY00030.${dateTime}.pdf -#printf "latestChart filename: %s\n" ${latestChart} + echo "${nowDate}${fileTime}" +} -# -q no config file lookup -# -f fail early -# -s silent -curl -q -fs -o ${latestChart} ftp://ftp.bom.gov.au/anon/gen/fwo/${latestChart} -curlExit=$? +dateTime=$(DeriveTime) +latestChart="IDY00030.${dateTime}.pdf" +# -q no config file lookup -f fail on error -s silent +curlExit=0 +curl -q -fs -o "${latestChart}" "ftp://ftp.bom.gov.au/anon/gen/fwo/${latestChart}" \ + || curlExit=$? -if [ $curlExit -gt 0 ] ; then - # Did we find a file? (Maybe it has not been created yet). - if [ $curlExit -eq 78 ] ; then - echo "No file at remote site $curlExit" - # todo create a one-shot timer service +if [ "$curlExit" -gt 0 ]; then + if [ "$curlExit" -eq 78 ]; then + echo "No file at remote site: ${latestChart} (curl exit ${curlExit})" >&2 fi - exit $curlExit + exit "$curlExit" fi +magick -density 300 "${latestChart}" "${dateTime}.png" -magick -density 300 ${latestChart} ${dateTime}.png - +mv "${latestChart}" "${RAW_DIR}/" +cp "${dateTime}.png" "${ARCHIVE_DIR}/" +mv "${dateTime}.png" "${LATEST}" |
