Author

Topic: Bash script to sound when coins received - need debug (Read 1110 times)

full member
Activity: 309
Merit: 100
lol ;p

When I meant I haven't scripted against blockchain.info meant just that. i.e. I don't know there policies so just modified his script as is to hopefully point him in the right direction.

willing to help him further if he does have any questions though ;p


im curious if thats what he was looking for, as i only use linux for servers and not desktops and can't easily test the whole sound thing .

Kosta
full member
Activity: 126
Merit: 100
I kept the script as is, as I havn't scripted against blockchain.info, but Yes, the timing should be changed to make things nicer for them ;p


kosta

All that needs to be changed is

Code:
sleep 1s

to some other value, say 30 seconds:

Code:
sleep 30s
full member
Activity: 309
Merit: 100
I kept the script as is, as I havn't scripted against blockchain.info, but Yes, the timing should be changed to make things nicer for them ;p


kosta
full member
Activity: 126
Merit: 100
Good job, I like the ingenuity! I see two issues with your script:

1) It only checks if the amount is over 0. You should save the balance at startup (such as initbalance) so users that already have balances can use it.

2) Your abusing the free API access pretty badly, and you might unknowingly run into your 8 hour limit within 3 hours.

From the bottom of https://blockchain.info/api

Requests in 8 Hours: (Maximum : 10000)
Requests in 5 minutes: (Maximum : 500)

Your making 28800 (if curl responds instantly) api calls in a 8 hour period. I would suggest polling every 3 seconds to barely make it in the limits (9600 requests a day) or 10+ seconds to be nice to blockchain.info for their free api service. I personally don't need to know that second that I received some coins.

Other than that, keep up the great work!
full member
Activity: 309
Merit: 100
Made some changes. Please note I haven't tested thoroughly and I didnt have time to test on a linux box, so could not install pulseaudio


Code:
#!/bin/sh
#needs:
# - pulseaudio - for paplay
# - curl
# - blockexplorer not 404

address=$1
confirmations="6"
balance=$(curl --fail "http://blockexplorer.com/q/getreceivedbyaddress/$address/$confirmations") || { echo "Unable to retrieve balance" >&2; exit 1; }


while [ `echo ${balance} == 0| bc` -eq 1 ]
do
 sleep 1s
 echo ${balance}
done


echo ${balance} at ${address} received with ${confirmations} confirmations.
paplay /usr/share/sounds/startup3.wav
hero member
Activity: 900
Merit: 1000
Crypto Geek
Goal: Make a sound when balance at an address reaches a set number of confirmations

So far:

Code:
#needs:
# - pulseaudio - for paplay
# - curl
# - blockexplorer not 404

address=$1
confirmations="6"
balance=$(curl --fail "http://blockexplorer.com/q/getreceivedbyaddress/$address/$confirmations") || { echo "Unable to retrieve balance" >&2; exit 1; }



while $BALANCE=0
do
 sleep 1s
 echo $BALANCE
done


echo $BALANCE at $ADDRESS received with $CONFIRMATIONS confirmations.
paplay /usr/share/sounds/startup3.wav

Needs a bit of tweaking.

I did a search and found bash scripts in this dev section so I'm posting here... but it doesn't seem the best section to post in, sorry if it's wrong
Jump to: