Short how-to: BASH script to manually check current Bitcoin price

I’m not much intro cryptocurrencies but I got this nice script that outputs the price of Bitcoin when invoked:

$ cat /usr/bin/bitcoin

#!/bin/bash
curl -s http://api.coindesk.com/v1/bpi/currentprice.json | python -c "import json, sys; print(json.load(sys.stdin)['bpi']['USD']['rate'])"

It’s simple and effective. Maybe someone finds a use for this.
It practically reads an online JSON database file via the Coindesk API using curl and then uses Python to read certan tables from that JSON file.

Screenshot%20at%202019-03-04%2005-24-36

1 Like

Another alternative could be to use jq command to parse the JSON format instead of parsing JSON with python.

For example:

$ curl -s http://api.coindesk.com/v1/bpi/currentprice.json  | jq '.bpi.USD.rate'
"3,756.9767"
$ curl -s http://api.coindesk.com/v1/bpi/currentprice.json  | jq '.bpi.GBP.rate'
"2,854.7436"
$ curl -s http://api.coindesk.com/v1/bpi/currentprice.json  | jq '.bpi.EUR.rate'
"3,316.9031"

1 Like

That’s very cool. Didn’t know about jq.