From 054ad96ec2740c1736fbb4a93777d0a49775b139 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 19 Aug 2017 16:14:42 +0200 Subject: [PATCH] [modules/getcrypto] Simplify code a bit Make codeclimate happy... --- bumblebee/modules/getcrypto.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index 7680e4f..0884463 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -21,20 +21,18 @@ import bumblebee.output import bumblebee.engine from requests.exceptions import RequestException def getfromkrak(coin,currency): - if coin=='Btc': - epair = "xbt"+currency - tickname = "XXBTZ"+currency.upper() - if coin=='Eth': - epair = "eth"+currency - tickname = "XETHZ"+currency.upper() - if coin=='Ltc': - epair = "ltc"+currency - tickname = "XLTCZ"+currency.upper() + abbrev = { + "Btc": ["xbt", "XXBTZ"], + "Eth": ["eth", "XETHZ"], + "Ltc": ["ltc", "XLTCZ"], + } + data = abbrev.get(coin, None) + if not data: return + epair = "{}{}".format(data[0], currency) + tickname = "{}{}".format(data[1], currency.upper()) try: krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() - except RequestException: - return "No connection" - except Exception: + except (RequestException, Exception): return "No connection" kethusdask = float(krakenget['result'][tickname]['a'][0]) kethusdbid = float(krakenget['result'][tickname]['b'][0])