2014-09-23 21:03:23 +00:00
|
|
|
#!/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
|
2014-09-23 21:03:23 +00:00
|
|
|
#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`
|
2014-09-23 21:03:23 +00:00
|
|
|
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
|
|
|
|
|