[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)
This commit is contained in:
Bart Geesink 2017-06-24 17:41:40 +02:00
parent d69f13f0b4
commit 43a25486ba

View file

@ -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"
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]