dotfiles/Utils/BTC_stats.sh

33 lines
755 B
Bash
Raw Normal View History

#!/bin/bash
file=/dev/shm/btc_stats
fileURL=http://api.bitcoincharts.com/v1/weighted_prices.json
function update_file {
wget --quiet $fileURL -O $file
#echo WILL_WGET
}
2014-09-30 21:47:26 +00:00
if [ -s $file ]; then
#update if older than 1h
age=`stat -c %Y $file`;
now=`date +%s`;
diff=$(($now - $age));
if [ $diff -gt 3600 ]; then
update_file & #Do not hang the result
fi;
#Fucking ugly, but works
content=`cat $file | python -mjson.tool | grep -A3 EUR | tail -n3 | cut -d':' -f2 | cut -d'"' -f2`;
2014-09-30 21:47:26 +00:00
p24h=`echo "$content" | sed -n 1p | cut -d. -f1`
p7d=`echo "$content" | sed -n 3p`
p30d=`echo "$content" | sed -n 2p`
graph=`sparklines $p30d $p7d $p24h`
echo $graph [$p24h] #dont want sparklines newline
else
update_file & #Will surely wait for iface
fi