2014-01-04 19:21:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-01-05 10:54:46 +00:00
|
|
|
# (C) Matthew Slowe, 2014
|
|
|
|
# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
|
|
|
|
# http://creativecommons.org/licenses/by-sa/4.0/
|
2014-01-04 19:21:37 +00:00
|
|
|
|
|
|
|
CACHE=/tmp/river_level_.dat
|
|
|
|
checkdata () {
|
|
|
|
if test `find "$CACHE" -mtime +1`
|
|
|
|
then
|
|
|
|
curl -o $CACHE -Ss $URLBASE || exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getstationname () {
|
|
|
|
checkdata
|
|
|
|
NAME=$( perl -MJSON::PP -e '
|
|
|
|
open $fh, "/tmp/river_level_.dat" or die $!;
|
|
|
|
$data_arr = decode_json(<$fh>) or die $!;
|
|
|
|
my %data;
|
|
|
|
foreach (@{$data_arr->{data}}) {
|
|
|
|
$data{$_->{id}} = $_;
|
|
|
|
}
|
|
|
|
foreach (@ARGV) { print $data{$_}->{river}, " at ", $data{$_}->{station}, "\n"; }
|
|
|
|
' $* )
|
|
|
|
}
|
|
|
|
|
|
|
|
STATION=$(basename $0 | sed 's/^river_level_//g' | cut -d_ -f 3)
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
echo "no"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "suggest" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
getstationname $STATION
|
|
|
|
echo "graph_title River Level for $NAME [$STATION]"
|
|
|
|
echo 'graph_args --base 1000 -l 0 '
|
|
|
|
echo 'graph_vlabel station level (metres)'
|
|
|
|
echo 'graph_category rivers'
|
|
|
|
echo 'graph_info This graph shows river levels'
|
|
|
|
echo "level.label $NAME"
|
|
|
|
echo 'level.info Current river level (metres)'
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
curl -sS $URLBASE/$STATION |
|
|
|
|
perl -MJSON::PP -e '$d=decode_json(<>) or die; print "level.value $d->{data}->{current}->{level}\n";'
|
|
|
|
|