From 2f40c6d1a27194d68813b141c71caf8b735de17b Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Tue, 28 Jul 2020 21:52:18 +0200 Subject: [PATCH] Fix crypto script --- .local/bin/scripts/dwmbar/crypto | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/.local/bin/scripts/dwmbar/crypto b/.local/bin/scripts/dwmbar/crypto index 00611e1..a3e9530 100755 --- a/.local/bin/scripts/dwmbar/crypto +++ b/.local/bin/scripts/dwmbar/crypto @@ -5,17 +5,22 @@ import json def __LBC(): - data = subprocess.run( - ["lbrynet", "account", "list"], stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - if data.stderr != b'': + try: + data = subprocess.run( + ["lbrynet", "account", "list"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + if data.stderr != b"": + return None + data = json.loads(data.stdout) + balance: float = 0 + for i in range(len(data["items"])): + d = data["items"][i]["coins"] + balance += float(d) + return round(balance, 1) + except json.decoder.JSONDecodeError: return None - data = json.loads(data.stdout) - balance: float = 0 - for i in range(len(data["items"])): - d = data["items"][i]["coins"] - balance += float(d) - return round(balance, 1) def __DOGE(): @@ -25,7 +30,7 @@ def __DOGE(): stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) - if data.stderr != b'': + if data.stderr != b"": return None balance = json.loads(data.stdout) return round(balance, 1) @@ -40,7 +45,7 @@ def __BTC(): stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) - if data.stderr != b'': + if data.stderr != b"": return None balance = json.loads(data.stdout) return round(balance, 1)