#!/bin/bash
set -x
SITE="http://www.reddit.com/"
REDDIT="${@}"
getUSD () {
curl -s "http://blockchain.info/ticker" |\
grep '"USD"' |\
egrep -o "\"24h\" : [[:digit:]]{1,3}\.[[:digit:]]{0,8}" |\
sed 's/"24h" : //'
}
getBTC () {
total=0
while read i; do
total=$( bc <<< "scale=8; $total+$i" )
done <<< "$( \
curl -s "$@" |\
sed '1,/class="sitetable nestedlisting"/d' |\
egrep -o "\+(bit|btc|tip)(.*)</p>" |\
sed -ne 's/<[\/]\?[a-zA-Z_=0-9]\+>//g; s/^\+[[:alpha:]]\+[ ]\?[\@]\?[[:alnum:]]* \([\.]\?[[:digit:]]\)/\1/p' |\
egrep -o "(\.?)[[:digit:]]+(\.?)[[:digit:]]*" \
)"
echo $total
}
btcInUSD () {
long_number=$( bc <<< "scale=2; ${USDVALUE}*${TOTALBTC}" )
printf "%.2f\n" "$long_number"
}
USDVALUE="$( getUSD )"
TOTALBTC="$( getBTC "${SITE}${REDDIT}" )"
printf "\nTotal BTC:\t${TOTALBTC}\nBTC in USD(\$):\t$(btcInUSD)\nPrice USD:\t${USDVALUE}\n\n"