spacepaste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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"