[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:
parent
d69f13f0b4
commit
43a25486ba
1 changed files with 7 additions and 1 deletions
|
@ -17,6 +17,7 @@ import time
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
def getfromkrak(coin):
|
def getfromkrak(coin):
|
||||||
if coin=='Btc':
|
if coin=='Btc':
|
||||||
|
@ -28,7 +29,12 @@ def getfromkrak(coin):
|
||||||
if coin=='Ltc':
|
if coin=='Ltc':
|
||||||
epair = "ltcusd"
|
epair = "ltcusd"
|
||||||
tickname = "XLTCZUSD"
|
tickname = "XLTCZUSD"
|
||||||
|
try:
|
||||||
krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json()
|
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])
|
kethusdask = float(krakenget['result'][tickname]['a'][0])
|
||||||
kethusdbid = float(krakenget['result'][tickname]['b'][0])
|
kethusdbid = float(krakenget['result'][tickname]['b'][0])
|
||||||
return coin+": "+str((kethusdask+kethusdbid)/2)[0:6]
|
return coin+": "+str((kethusdask+kethusdbid)/2)[0:6]
|
||||||
|
|
Loading…
Reference in a new issue