summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-04-20 18:03:53 +1200
committerDavid Phillips <david@sighup.nz>2017-04-20 18:03:53 +1200
commitf8f974f175f964a6f147e72299a1898c50bfce50 (patch)
tree2c0a95c2372d1adb58ba77ee0d989fc5fa27a019
parent61ddee05adf0934cd5e723f9941d39e15070cbac (diff)
downloaddotfiles-f8f974f175f964a6f147e72299a1898c50bfce50.tar.xz
Make currency more extensible
-rw-r--r--bashrc6
-rwxr-xr-xlocal/bin/grab-spot6
-rwxr-xr-xlocal/bin/update-dwm-bar9
3 files changed, 13 insertions, 8 deletions
diff --git a/bashrc b/bashrc
index 3749f15..fb322db 100644
--- a/bashrc
+++ b/bashrc
@@ -48,5 +48,7 @@ if [ -f ~/.cache/weather/forecast ]; then
fi
[ -d ~/Maildir/new/ ] && [ "$(ls ~/Maildir/new/)" ] && echo 'New mail'
-[ -f ~/.cache/XAGNZD ] && echo "$(cat ~/.cache/XAGNZD) (at $(date +"%a %d %H:%M" --date=@$(stat -c %Y ~/.cache/XAGNZD)))"
-[ -f ~/.cache/XAUNZD ] && echo "$(cat ~/.cache/XAUNZD) (at $(date +"%a %d %H:%M" --date=@$(stat -c %Y ~/.cache/XAUNZD)))"
+
+[ -z "$(ls -A ~/.cache/currency)" ] || for c in ~/.cache/currency/* ; do
+ echo "$(cat $c) (at $(date +"%a %d %H:%M" --date=@$(stat -c %Y $c)))"
+done
diff --git a/local/bin/grab-spot b/local/bin/grab-spot
index 989d037..d912d7a 100755
--- a/local/bin/grab-spot
+++ b/local/bin/grab-spot
@@ -8,7 +8,7 @@
# for example, to get the value of USD in NZD:
# grab-spot USD NZD
# would place a file at ~/.cache/USDNZD containing the value of the USD in NZD,
-# to 4 decimal places
+# to 4 decimal places, and a label for the conversion
if [ -z $1 ]; then
logger "$0: blank FROM currency"
@@ -19,8 +19,8 @@ if [ -z $2 ]; then
exit
fi
-# Only bother downloading if it's more than 3 hours old
-if ([ ! -f ~/.cache/"$1$2" ] || [ $(find ~/.cache/"$1$2" -mmin +60) ]) ; then
+# Only bother downloading if it's more than 1 hour old
+if ([ ! -f ~/.cache/currency/"$1$2" ] || [ $(find ~/.cache/currency/"$1$2" -mmin +60) ]) ; then
rate=$(curl "http://rate-exchange-1.appspot.com/currency?from=$1&to=$2" | jshon -e rate)
if [ $? -ne 0 ] ; then
logger "$0: curl error"
diff --git a/local/bin/update-dwm-bar b/local/bin/update-dwm-bar
index ac68582..bde7aeb 100755
--- a/local/bin/update-dwm-bar
+++ b/local/bin/update-dwm-bar
@@ -7,8 +7,11 @@ while true; do
if hash upsc 2>/dev/null; then
ups="UPS: $(upsc eaton5e@zoidberg battery.charge)% $sep "
fi
- if [ -f ~/.cache/XAGNZD ]; then
- xa="$(cat ~/.cache/XAGNZD) $(cat ~/.cache/XAUNZD) $sep "
+ if [ ! -z "$(ls -A ~/.cache/currency/)" ] ; then
+ for c in ~/.cache/currency/* ; do
+ currency="$currency$(cat $c) "
+ done
+ currency="$currency$sep "
fi
if [ -d "/sys/class/power_supply/BAT0/" ]; then
bat="$(cat /sys/class/power_supply/BAT0/capacity)%"
@@ -35,7 +38,7 @@ while true; do
done
thermal_string="${thermal_string%,} °C"
datetime_string=$(date "+%A $sep %d %h %Y $sep %_I:%M %p (UTC%:::z)")
- xsetroot -name "$xa$ups$thermal_string $sep $bat_string$datetime_string" || exit
+ xsetroot -name "$currency$ups$thermal_string $sep $bat_string$datetime_string" || exit
sleep "$DELAY"
done