From 43a25486ba2ce6fc1f2caaff58b6707a2757af6d Mon Sep 17 00:00:00 2001 From: Bart Geesink Date: Sat, 24 Jun 2017 17:41:40 +0200 Subject: [PATCH 1/2] [modules/getcrypto] Add error handling to the api request. This prevents a bumblebee crash when no internet connection is present (like when a laptop resumes from sleep mode) --- bumblebee/modules/getcrypto.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index 1f0aed7..f4565ba 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -17,6 +17,7 @@ import time import bumblebee.input import bumblebee.output import bumblebee.engine +from requests.exceptions import RequestException def getfromkrak(coin): if coin=='Btc': @@ -28,7 +29,12 @@ def getfromkrak(coin): if coin=='Ltc': epair = "ltcusd" tickname = "XLTCZUSD" - krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() + try: + krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() + except RequestException: + return "No connection" + except Exception: + return "No connection" kethusdask = float(krakenget['result'][tickname]['a'][0]) kethusdbid = float(krakenget['result'][tickname]['b'][0]) return coin+": "+str((kethusdask+kethusdbid)/2)[0:6] From 915cfc681adb168c172361d486fec84479958b66 Mon Sep 17 00:00:00 2001 From: Bart Geesink Date: Mon, 26 Jun 2017 22:35:33 +0200 Subject: [PATCH 2/2] [modules/getcrypto] Add the option to display the price in other currencies than USD. --- bumblebee/modules/getcrypto.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index f4565ba..6eb42fe 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -10,6 +10,7 @@ Parameters: * getcrypto.getbtc: 0 for not getting price of BTC, 1 for getting it (default). * getcrypto.geteth: 0 for not getting price of ETH, 1 for getting it (default). * getcrypto.getltc: 0 for not getting price of LTC, 1 for getting it (default). + * getcrypto.getcur: Set the currency to display the price in, usd is the default. """ import requests @@ -18,17 +19,16 @@ import bumblebee.input import bumblebee.output import bumblebee.engine from requests.exceptions import RequestException - -def getfromkrak(coin): +def getfromkrak(coin,currency): if coin=='Btc': - epair = "xbtusd" - tickname = "XXBTZUSD" + epair = "xbt"+currency + tickname = "XXBTZ"+currency.upper() if coin=='Eth': - epair = "ethusd" - tickname = "XETHZUSD" + epair = "eth"+currency + tickname = "XETHZ"+currency.upper() if coin=='Ltc': - epair = "ltcusd" - tickname = "XLTCZUSD" + epair = "ltc"+currency + tickname = "XLTCZ"+currency.upper() try: krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() except RequestException: @@ -51,6 +51,7 @@ class Module(bumblebee.engine.Module): self._getbtc = int(self.parameter("getbtc", "1")) self._geteth = int(self.parameter("geteth", "1")) self._getltc = int(self.parameter("getltc", "1")) + self._getcur = self.parameter("getcur", "usd") engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd="xdg-open https://cryptowat.ch/") @@ -60,13 +61,14 @@ class Module(bumblebee.engine.Module): def update(self, widgets): if self._nextcheck < int(time.time()): self._nextcheck = int(time.time()) + self._interval + currency = self._getcur btcprice, ethprice, ltcprice = "", "", "" if self._getbtc==1: - btcprice= getfromkrak('Btc') + btcprice= getfromkrak('Btc',currency) if self._geteth==1: - ethprice=getfromkrak('Eth') + ethprice=getfromkrak('Eth',currency) if self._getltc==1: - ltcprice=getfromkrak('Ltc') + ltcprice=getfromkrak('Ltc',currency) self._curprice = btcprice+" "*(self._getbtc*self._geteth)+ethprice+" "*(self._getltc*max(self._getbtc, self._geteth))+ltcprice # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4