Summary: make bar graphs prettier. Unicode FTW!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-03-02 09:21:07 +10:30
parent 5cf676f814
commit 16dc96263a
3 changed files with 81 additions and 45 deletions

View File

@@ -1,7 +1,8 @@
# Summary plugin
This plugin is a little hack to show a summary of your node, including
fiat amounts.
fiat amounts. If you have pylightning 0.0.7.1 or above, you get nice linegraphs,
otherwise normal ASCII.
## Options:
@@ -18,41 +19,38 @@ $ lightning-cli summary | tr ',' '\n'
{"network": "TESTNET"
"my_address": "031a3478d481b92e3c28810228252898c5f0d82fc4d07f5210c4f34d4aba56b769@165.227.30.200"
"num_utxos": 5
"utxo_amount": "1.20119332000btc = USD $4589.24"
"num_channels": 31
"num_connected": 1
"num_gossipers": 32
"avail_out": "0.27095103btc = USD $1035.19"
"avail_in": "2.06940379btc = USD $7906.30"
"channels": [" ---------------------------/ :02ac05912f89e43b88de3472e8c3003b"
" -------------------------/- :02dd4cef0192611bc34cd1c3a0a7eb0f"
" /--------------------------- :02a13878947a133d7c96e70303a9bf27 (priv)"
" /- :033e2db012833d997e3c"
" /-- :Kenny_Loggins"
"/--------------------------------------------- :DeutscheTestnetBank"
"/--------------------------------------------- :BlueLagoon1"
"/--------------------------------------------- :0270dd38e8af9a64b4a483ab12b6aeb1"
" /-- :btctest.lnetwork.tokyo"
" /----- :microbet.fun"
"/--------------------------------------------- :02fcab6e34a2ad21be2a752ab96d13f5 (priv)"
"/--------------------------------------------- :htlc.me"
" /-------- :02229ea9a7a4f9bf8bf25ce225079aed"
"/--------------------------------------------- :025d5b572a94235cfcbdc429181b2b88"
" /------------------------- :03c56de3a84336b4a939777ace9ecbef (priv)"
" /------------------ :LiteStrikeBTClnd"
" /---------------------------------- :037c9cf1cde4414c59407d547b7eac08 (priv)"
" / :03490a74e4def9125a84aee2d84e8cfe"
" ---------------------/--------------------- :aranguren.org"
" / :03cc6603e1f6df535dd8b423284f2c09 (priv)"
" /- :cyclopes"
"/--------------------------------------------- :02b73a2160863e925e9fa978b0ddc56b (priv)"
" /-------- :lnd-testnet.ignios.net"
" /----- :0327a104108173d4a4f34ab2cbc3084c (priv)"
" /---- :dwarf"
" /- :028133777757ce281658804dd82f5758 (priv)"
" /------------------------- :02db62ffff5c35be74e7f856bba136db (priv)"
" / :Lightning Tea"
" /-- :03015ac044f5fa9768ededf6fed9c0ff (priv)"
" /-- :LND-Neutrino-TEST"
"/--------------------------------------------- :0270685ca81a8e4d4d01"]}
```
"utxo_amount": "1.20119332000btc = USD $4476.10"
"num_channels": 29
"num_connected": 4
"num_gossipers": 27
"avail_out": "0.27095103btc = USD $1009.67"
"avail_in": "2.05851379btc = "
"channels": [" ├────────────╢ :02ac05912f89e43b88de3472e8c3003b"
" ├───────────╢ :02dd4cef0192611bc34cd1c3a0a7eb0f"
" ╟────────────┤ :02a13878947a133d7c96e70303a9bf27 (priv)"
" :033e2db012833d997e3c"
" ╟┤ :Kenny_Loggins"
" ╟──────────────────────┤:DeutscheTestnetBank"
" ╟─────────────────────┤ :BlueLagoon1"
" ╟──────────────────────┤:0270dd38e8af9a64b4a483ab12b6aeb1"
" ╟┤ :btctest.lnetwork.tokyo"
" ╟─┤ :microbet.fun"
" ╟──────────────────────┤:02fcab6e34a2ad21be2a752ab96d13f5 (priv)"
" ╟──────────────────────┤:htlc.me"
" ╟───┤ :02229ea9a7a4f9bf8bf25ce225079aed"
" ╟─────────────────────┤ :025d5b572a94235cfcbdc429181b2b88"
" ╟────────────┤ :03c56de3a84336b4a939777ace9ecbef (priv)"
" ╟────────┤ :LiteStrikeBTClnd"
" ╟────────────────┤ :037c9cf1cde4414c59407d547b7eac08 (priv)"
" :03490a74e4def9125a84aee2d84e8cfe"
" ├─────────┼─────────┤ :aranguren.org"
" :03cc6603e1f6df535dd8b423284f2c09 (priv)"
" :cyclopes"
" ╟─────────────────────┤ :02b73a2160863e925e9fa978b0ddc56b (priv)"
" ╟───┤ :lnd-testnet.ignios.net"
" ╟─┤ :0327a104108173d4a4f34ab2cbc3084c (priv)"
" ╟─┤ :dwarf"
" :028133777757ce281658804dd82f5758 (priv)"
" ╟────────────┤ :02db62ffff5c35be74e7f856bba136db (priv)"
" ╟┤ :03015ac044f5fa9768ededf6fed9c0ff (priv)"
" ╟──────────────────────┤:0270685ca81a8e4d4d01"]}

View File

@@ -1,2 +1,3 @@
pylightning>=0.0.6
requests>=2.0.0
packaging>=14.1

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env python3
from lightning import Plugin, Millisatoshi
from packaging import version
from collections import namedtuple
import lightning
import json
import requests
import threading
@@ -7,6 +10,21 @@ import time
plugin = Plugin(autopatch=True)
have_utf8 = False
# __version__ was introduced in 0.0.7.1, with utf8 passthrough support.
try:
if version.parse(lightning.__version__) >= version.parse("0.0.7.1"):
have_utf8 = True
except Exception:
pass
Charset = namedtuple('Charset', ['double_left', 'left', 'bar', 'mid', 'right', 'double_right', 'empty'])
if have_utf8:
draw = Charset('', '', '', '', '', '', '')
else:
draw = Charset('#', '[', '-', '/', ']', '#', '|')
class PriceThread(threading.Thread):
def __init__(self):
@@ -94,13 +112,32 @@ def summary(plugin):
if chans != []:
reply['channels'] = []
biggest = max(int(c[0]) for c in chans)
biggest = max(max(int(c[1]), int(c[2])) for c in chans)
for c in chans:
# Create simple line graph
s = ('-' * int((int(c[1]) / biggest * 46))
+ '/' + '-' * int((int(c[2]) / biggest * 46)))
# Center it
s = "{:^47}".format(s)
# Create simple line graph, 47 chars wide.
our_len = int((int(c[1]) / biggest * 23))
their_len = int((int(c[2]) / biggest * 23))
divided = False
# We put midpoint in the middle.
mid = draw.mid
if our_len == 0:
left = "{:>23}".format('')
mid = draw.double_left
else:
left = "{:>23}".format(draw.left + draw.bar * (our_len - 1))
if their_len == 0:
right = "{:23}".format('')
# Both 0 is a special case.
if our_len == 0:
mid = draw.empty
else:
mid = draw.double_right
else:
right = "{:23}".format(draw.bar * (their_len - 1) + draw.right)
s = left + mid + right
node = plugin.rpc.listnodes(c[3])['nodes']
if len(node) != 0:
s += ':' + node[0]['alias']