Visualiser une révision

[Debian/Ubuntu] Conky : Afficher prix du Bitcoin/Dash et la quantité sur le compte

voxdemonix : révision n°6 (20 décembre 2019 16:30:30)

![screenshot conky bitcoin](https://gitlab.com/voxdemonix/conky/raw/master/conky_bitcoin_rate/screenshot-2019_11_29-conky_bitcoin_rate1.jpg)

Si vous ne souhaitez pas éditer le code, alors créez le dossier _/home/your_username/.conky/conky-perso/conky_bitcoin_rate_ et ajoutez les codes source suivants dedans. Installez aussi [tor](https://manpages.ubuntu.com/manpages/disco/en/man1/tor.1.html) et [curl](https://manpages.ubuntu.com/manpages/disco/en/man1/curl.1.html) (_apt install tor curl_).

Gitlab : https://gitlab.com/voxdemonix/conky/tree/master/conky_bitcoin_rate

**Code source du fichier conkyrc (ajoutez le code dans _~/.conky/conky-perso/conky_bitcoin_rate/conkyrc_)**

```
# INFOS : https://linuxfr.org/wiki/debian-ubuntu-conky-afficher-prix-du-bitcoin-dash-et-la-quantite-sur-le-compte
# http://conky.sourceforge.net/config_settings.html
# Use Xft?
use_xft yes
xftfont Ubuntu Beta:size=8
xftalpha 0.8
text_buffer_size 2048

# Update interval in seconds
update_interval 300

# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0

# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_transparent no
own_window_argb_visual yes
own_window_argb_value 210  # semi-transparent
own_window_type normal
own_window_class conky
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
background no

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 200 20
maximum_width 500
maximum_height 100

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Stippled borders?
stippled_borders 0

# border margins
border_inner_margin 2

# border width
border_width 1

# Default colors and also border colors
default_color 00c4e7
default_shade_color black
default_outline_color white
own_window_colour black

# Text alignment, other possible values are commented
#alignment top_left
alignment tl
#alignment bottom_left
#alignment bottom_right

# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 300
gap_y 300

# Subtract file system buffers from usedmemory?
no_buffers yes

# set to yes if you want all text to be in uppercase
uppercase no

# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes

# Add spaces to keep things from moving about?  This only affects certain objects.
use_spacer none


TEXT
${execp ~/.conky/conky-perso/conky_bitcoin_rate/bitcoin_rate.bash }
```


Le code source du fichier _bitcoin_rate.bash_ (ajoutez le dans _~/.conky/conky-perso/conky_bitcoin_rate/bitcoin_rate.bash_). Si vous n'utilisez pas Tor, supprimez “_torsocks_” dans les commandes.

```bash
#!/bin/bash
# Gitlab : https://gitlab.com/voxdemonix/conky/blob/master/conky_bitcoin_rate/
btcAddr='YOUR_BiTCoin_ACCOUNT_HERE';
 
[ $(cat /tmp/${USER}_PRIVACON 2>&1 | grep -Eo "0|1") ] && exit # PRIVACON, stop if most alert (1) or Ghost mode (0)
PRIVACON=$(cat /tmp/${USER}_PRIVACON 2>&1 | grep -Eo "[0-9]");
[ -z "$PRIVACON" ] && PRIVACON=6 # set privacon to 6 if undectected
 
echo -n '${color yellow}Account BTC : '
 
if [ "$PRIVACON" -gt 3 ]; then
	raw=$(torsocks curl --max-time 10 "https://blockchain.info/q/addressbalance/$btcAddr");
	echo "$raw" | grep -Eo '^([0-9]{1,}([.]{1}[0-9]{1,}){0,1}){1}$' | sed \':a;N;$!ba;s/\n//g\' || account=$( echo "scale=8; $raw/100000000" | bc | sed 's/^\./0\./' ); echo -n "$account"
else
	echo -n "\${color red}\${font Symbola :size=9}⛔\${font}\${color}\${color yellow}"
	account=0
fi
 
echo -n ' ${font Symbola:size=10}₿${font}${color}'
raw=$(torsocks curl --max-time 10 'https://api.coindesk.com/v1/bpi/currentprice/EUR.json');
euro=$(echo "$raw"  | grep -oP '(?<="Euro","rate_float":).*?(?=\})');
dollars=$(echo "$raw" | grep -oP '(?<="United States Dollar","rate_float":).*?(?=\})' | sed 's/\./,/');
balance=$(bc<<<$account*$euro)
balance=${balance%.*}
echo " (\${color orange}$balance€\${color})"
euro=$(echo -n "$euro" | sed 's/\./,/')
echo -n '${alignc}'; printf %.2f $dollars; echo -n ' USD <~~ BITCOIN ~~> ';  printf %.2f $euro; echo -n ' EURO';
echo
raw=$(torsocks curl --max-time 10 'https://min-api.cryptocompare.com/data/price?fsym=DASH&tsyms=USD,EUR'); euro=$(echo "$raw"  | grep -oP '(?<="EUR":).*?(?=})' | sed 's/\./,/'); dollars=$(echo "$raw" | grep -oP '(?<="USD":).*?(?=,)' | sed 's/\./,/'); echo -n '${alignc}'; printf %.2f $dollars; echo -n ' USD <~~ DASH ~~> ';  printf %.2f $euro; echo -n ' EURO';
```