You are not logged in.
Pages: 1
I created another little script that allows me to utilize some python functionality built into electrum and show some bitcoin information in my conky.
From the README:
show_bitcoin is a simple python script that levarages information
from an electrum wallet, along with current bit coin pricing to
format and print out the amount of bitcoin in the wallet, the current
price for bitcoing and the current estimated fiat currency value of
the bitcoin stored in the electrum wallet.The current iteration of this script is in its early stages. At the
moment is uses font1 & font2 as two variables that define the fonts and
colors formatted for output to conky.TO DO: implement an arg parser to pass in the font arguments.
Useage: Assuming the script is stored in ~/bin then issue
${execpi 60 ~/bin/show_bitcoin}
into your conky. Output will be formatted for conky using values stored
in font1 & font2 in show_bitcoin
The python code is going to do a couple of things. First, it is going to go out to coinbase.com and read the latest bitcoin prices. It will then pull the balance from your electrum wallet. This, of course, assumes that you have a correctly setup electrum wallet and that you have some bitcoin stored in it. It will then multiply the balance by the latest bitcoin price from coinbase.com. he resulting value is an approximation of USD worth of bitcoin.
The code is a bit fiddly and I need to write an arg parser for it, but I have been monitoring it for several days and it seems to accomplish what I wanted it to do:
#! /usr/bin/python
# A simple utility that will calculate bitcoin balance from an electrum wallet.
# Requires: electrum
# Assumes: you currently have bitcoin stored in an electrum wallet.
# Author: William Bradley
# BunsenLabs Forum Handle: tknomanzr
# License: wtfpl. Use this script however you see fit.
import json, urllib2, subprocess
url = 'https://coinbase.com/api/v1/prices/historical'
font1 = "${font Exo-Bold:size=11}${color 0047ab}"
font2 = "${font Open-Sans:size=9}${color FF4500}"
# Get current bitcoin price
price = urllib2.urlopen(url)
price_data = price.read(34)
price_data = price_data[26:-2]
price_data = float(price_data)
# Get balance from wallet.
# It comes in as a json object that needs to be converted.
balance = json.loads(subprocess.check_output(["electrum","getbalance"]))
current_balance = balance['confirmed']
current_balance = float(current_balance)
# Get approximate value of bitcoin in wallet.
value = price_data * current_balance
print font1 + "Current Price: " + font2 + str(price_data)
print font1 + "BTC Balance: " + font2 + str(current_balance)
print font1 + "Approximate Value: " + font2 + str(round(value,2)) + " USD"
Scrot it or it didn't happen:
Note: I ended up running electrum as a subprocess because I could not figure out how to import it as a module and gain access to any methods it exposes.
Last edited by tknomanzr (2017-08-17 18:53:18)
Offline
I think this is cool! Thx!
It might be also an option to show the price only, without the balance. Or - as a vague idea for future development - to have the balance updated when electrum gets opened. In that case there would be no need for that subprocess.
Anyhow, great feature, I like it.
Offline
This is definitely a rough first draft. I think I have figured out a way to gain more control of the output by classing these little conky programs out. As this version currently stands, it just spits out three strings that also include all the necessary conky formatting. By classing it out, I could call various parts of the program like show_bitcoin.value(), show_bitcoin.balance(), etc.This way, the user could then specify where and when to print out a specific value in conky. Then conky formatting also becomes a user problem and not my problem which I like.
I also need to look at whether the published price is a json object or not. If it is, then I am managing the info wrong as I just literally went in and sliced out what I needed. If the output ever changes, then the program will break. If I can get properly structured data, then it would probably also be possible to graph out historical prices in conky, as I know for sure the data was in a list. The possibilities are endless with this one, however. I look forward to getting a chance to re-write it.
Offline
Good idea on calling the electrum balance! In what case would you use such a script? I mean, you have a continously changing electrum balance?
I use this code just to pull prices from kraken, I paste it just for reference as it is the topic. Uses curl, jq and grep.
Hope it can help a bit, to get structured data I would use the same method.
This is how it looks like
${font Monospace:bold:size=10}${alignc}${color2}C R Y P T O
${color1}${hr}
${font Monospace:normal:size=8}${color1} ETH ${texeci 300 curl https://api.kraken.com/0/public/Ticker?pair=XETHZEUR | jq ".result.XETHZEUR.c[0]" | grep -oE "[0-9]*\....."}
${font Monospace:normal:size=8}${color1} BTC ${texeci 300 curl https://api.kraken.com/0/public/Ticker?pair=XXBTZEUR | jq ".result.XXBTZEUR.c[0]" | grep -oE "[0-9]*\....."}
${font Monospace:normal:size=8}${color1} LTC ${texeci 300 curl https://api.kraken.com/0/public/Ticker?pair=XLTCZEUR | jq ".result.XLTCZEUR.c[0]" | grep -oE "[0-9]*\....."}
${font Monospace:normal:size=8}${color1} EOS ${texeci 300 curl https://api.kraken.com/0/public/Ticker?pair=EOSEUR | jq ".result.EOSEUR.c[0]" | grep -oE "[0-9]*\....."}
EDIT to make it clearer
Last edited by devnull (2017-08-31 12:32:45)
Offline
^Interesting
They can make a layman the terms
ETH
BTC
LTC
EOS
to explain?
Offline
hi unklar, sorry but I don't understand your question, I'm not native English. Could you rewrite it in a easier way?
Those are the names of the currencies (Ethereum, Bitcoin, Litecoin, Eos).
Eos doesn't work anymore with kraken api, but I mean, you just need to adapt the code to your needs
Offline
Thank you
I'm also not english!
Is there a link for the currencies?
PS: Thank you,
i found it myself
Conky: desktop window (2600117) is subwindow of root window (9e)
Conky: window type - normal
Conky: drawing to created window (0x6600002)
Conky: drawing to double buffer
sh: jq: Kommando nicht gefunden.
sh: jq: Kommando nicht gefunden.
sh: jq: Kommando nicht gefunden.
sh: jq: Kommando nicht gefunden.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Tot % Totala % Recl eived % Xferd Average Speed Time Time Time Curr % Receient
ved % Dload Upload Total Spen Xferd t Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 293 0 293 0 0 1318 0 --:--:-- --:--:-- --:--:-- 1583
(23) Failed writing body
sh: jq: Kommando nicht gefunden.
what is jq ?
please show this script.
Perhaps also interesting for Linux 8)
Last edited by unklar (2017-08-31 20:00:35)
Offline
Yeah, I will rework it to use an arg parser at some point. My electrum wallet balance does change at times, as I have purchased bandwith on a mining farm. Bitcoin's value has nearly quadrupled since I set it all up, so I have pretty much achieved full ROI. I just like to be able to keep an eye on it's rough value.
It is my intention to setup an etherium miner on my main box at some point and see how that goes. I may integrate some etherium wallet tracking at that point. The website I pull the price information from is completely arbitrary and there may be RESTful services out there that do a better job. At the moment, there is no consideration for localization or different fiat currencies other than US dollars.
Offline
what is jq ?
Hi,jq is a command line parser for json format. It should be pretty light and easy to use in many cases.
Just install it with apt-get
sudo apt-get install jq
Hope it helps
Offline
Offline
@devnull,
apology,
I have not written that this happens under Mageia 5. Here jq is unknown in this form as a package.
In bunsenlabs it works naturally!
Offline
@tknomanzr,
no problem.
Your python-script caused in mageia5 and also in bunsenlabs this error message (conky I have changed to the version 1.9):
conky -c ~/cryptoWaehrung/wtfbox_conkyrc9 &
[1] 2544
unklar@francescoPC:~$ Conky: forked to background, pid is 2545
Conky: desktop window (2c5) is root window
Conky: window type - normal
Conky: drawing to created window (0x3a00002)
Conky: drawing to double buffer
Traceback (most recent call last):
File "/home/unklar/bin/show_bitcoin", line 19, in <module>
balance = json.loads(subprocess.check_output(["electrum","getbalance"]))
File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
conky
#https://forums.bunsenlabs.org/viewtopic.php?pid=59768#p59768
#autor @tknomanzr
#30-08-2017
#modify 01-09-2017 @unklar
background yes
use_xft yes
xftfont monofur:size=10
xftalpha 1
update_interval 1
total_run_times 0
own_window yes
own_window_transparent yes
#own_window_colour 000000
own_window_type normal
own_window_argb_visual yes
#own_window_argb_value 200
own_window_hints undecorated,below,skip_taskbar,skip_pager #sticky,
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
default_shade_color 9999FF
default_outline_color b2b2FF
double_buffer yes
alignment br
#maximum_width 410
minimum_size 160 100 #375 500
gap_x 80
gap_y 280
text_buffer_size 2048
no_buffers yes
cpu_avg_samples 2
override_utf8_locale yes
TEXT
${color 0047ab}Electrum Wallet:${hr 2}
${execpi 60 ~/bin/show_bitcoin}
${color 0047ab}${hr 2}
Last edited by unklar (2017-09-01 17:18:04)
Offline
You have to be running an electrum wallet in order to use the script. If you are not familiar with electrum it is a bitcoin storage wallet, that exposes an api that I can leverage to get my current bitcoin balance. If you are not familiar with electrum, here is their page:
Electrum -- A Bitcoin wallet
Also, the wallet needs to be properly configured. The link should show you how to set it up. I don't have very good error trapping built into the script yet.
In Bunsenlabs:
sudo apt-get install electrum
electrum
If you already have an electrum wallet setup then you will need your passkey for a new wallet instance. If not, then it will walk you through the setup.
The error that was thrown is showing you that the command electrum cannot be found via the shell. If the command is not in your path, of course, then you either need to modify the script to provide the full path or add the path to your environment variables.
Similarly, if you do not have a wallet setup, python will throw another error.
Once those two conditions are fulfilled, meaning electrum is installed and configured, the script should parse the current bitcoin price, in USD, as obtained from coinbase.com. Then assuming you have any bitcoin stored in your wallet, it will calculate a USD value for the amount of bitcoin you have.
I realize this script is a very rough draft and is likely not very portable at the moment. I will try to work on it some more soon.
Offline
^Hi tknomanzr,
Thank you for your explanation.
If I understood correctly electrum is something like excodus to the administration
electronic money.
Since English is not my mother tongue, I have to be very careful and take a lot of time.
Besides, I have to ask "my government" if I can gamble with it. ]:D
I look forward to your work with Conky.
Offline
Pages: 1