Bitcoin Forum
January 27, 2021, 05:41:43 PM *
News: Latest Bitcoin Core release: 0.21.0 [Torrent]
   Home   Help Search Login Register More  
Pages: [1]
Author Topic: Sharing my Bitcoin Conky stuff  (Read 2565 times)
Hero Member
Offline Offline

Activity: 784
Merit: 1002


View Profile WWW
September 14, 2011, 01:57:16 AM

For Linux users I'd thought I'd just share a few bits of code I used to put Bitcoin stats in my conky config.

Since accessing the various site apis takes a bit of time and the conky exec functions are blocking (stops the other stats updating) I decided to do the updating as a separate cron job. This seems like the easiest approach.

First, here's a snippet of the resulting conky info on my screen:

I borrowed a nice little jsongrep python script from Terry Jones blog. I modified it slightly to output data using the json.dumps so that the unicode (u'') wouldn't be prefixed. I use this script from my conkybtc script to grab json data from some api calls.

(note that I like to put my scripts in a ~/.bin directory. they can be put wherever you prefer)
(just make sure they are in the path and chmod +x them)

#!/usr/bin/env python

import sys
import re
import json

def jsongrep(d, patterns):
        pattern = patterns.pop(0)
    except IndexError:
        print json.dumps(d, indent=4)
        if isinstance(d, dict):
            keys = filter(pattern.match, d.keys())
        elif isinstance(d, list):
            keys = map(int,
                              ['%d' % i for i in range(len(d))]))
            if pattern.match(str(d)):
                print json.dumps(d, indent=4)
        for item in (d[key] for key in keys):
            jsongrep(item, patterns[:])

if __name__ == '__main__':
        j = json.loads(
    except ValueError, e:
        print >>sys.stderr, 'Could not load JSON object from stdin.'

    jsongrep(j, map(re.compile, sys.argv[1:]))

Now my conkybtc script that is called by cron. You can mod this as you like to give different data or formatting. Also, you may want to mod it for some pool other than ArsBitcoin.


HSTYLE="\${font DejaVuSansMono:size=8.5}\${color red}"
DSTYLE="\${font DejaVuSansMono:size=8.5:style=bold}\${color white}"
SMALL="\${font DejaVuSansMono:size=7}"

DIFF=`curl -s`
BLK=`curl -s`
ARS=( `curl -sk$APIKEY |.bin/jsgrep "hashrate|totalPPSWork|paidPPSWork" |tr -d \"` )
GOX=( `curl -sk |.bin/jsgrep ticker "last|vol" |tr -d \"` )
_NR="`curl -s`*0.007158278"
_NXT=`curl -s`
NETHASH="`echo $_NR | bc`"

echo -e "${HSTYLE}Total BTC \${goto 87}${DSTYLE}${ARS[0]}\${goto 182}${HSTYLE}Confirmed BTC \$alignr${DSTYLE}${ARS[1]}" >$BUF
echo -e "${HSTYLE}MHash/s \${goto 87}${DSTYLE}${ARS[2]}\${goto 182}${HSTYLE}Network GHash/s \$alignr${DSTYLE}${NETHASH%%.*}" >>$BUF
echo -e "${HSTYLE}BlockCount \${goto 87}${DSTYLE}$BLK ${SMALL}($NXT)\${goto 182}${HSTYLE}Diffculty \$alignr${DSTYLE}${DIFF%%.*}" >>$BUF
echo -e "${HSTYLE}Last Price \${goto 87}${DSTYLE}${GOX[0]}\${goto 182}${HSTYLE}Volume BTC/24h\$alignr${DSTYLE}${GOX[1]}" >>$BUF

To add this to your cron, running every minute, use crontab -e and enter,

* * * * * ~/.bin/conkybtc

Finally, to make conky update the stats every 30 seconds (arbitrary) add a line like this to your .conkyrc file. This just inserts the data using cat, which means it's a quick update and other stuff still continues to update as well.

${color}${font DejaVuSansMono:style=bold:size=8.5}BitCoin $hr
${execpi 30 cat .conkybtc }

That's all folks!

Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!