[modules/getcrypto] quotes

This commit is contained in:
tobi-wan-kenobi 2020-04-19 10:35:27 +02:00
parent be63fdc059
commit 317f1f60b5

View file

@ -22,23 +22,23 @@ import bumblebee.engine
from requests.exceptions import RequestException from requests.exceptions import RequestException
def getfromkrak(coin, currency): def getfromkrak(coin, currency):
abbrev = { abbrev = {
"Btc": ["xbt", "XXBTZ"], 'Btc': ['xbt', 'XXBTZ'],
"Eth": ["eth", "XETHZ"], 'Eth': ['eth', 'XETHZ'],
"Ltc": ["ltc", "XLTCZ"], 'Ltc': ['ltc', 'XLTCZ'],
} }
data = abbrev.get(coin, None) data = abbrev.get(coin, None)
if not data: return if not data: return
epair = "{}{}".format(data[0], currency) epair = '{}{}'.format(data[0], currency)
tickname = "{}{}".format(data[1], currency.upper()) tickname = '{}{}'.format(data[1], currency.upper())
try: 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, Exception): except (RequestException, Exception):
return "No connection" return 'No connection'
if not 'result' in krakenget: if not 'result' in krakenget:
return "No data" return 'No data'
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]
class Module(bumblebee.engine.Module): class Module(bumblebee.engine.Module):
@ -46,15 +46,15 @@ class Module(bumblebee.engine.Module):
super(Module, self).__init__(engine, config, super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.curprice) bumblebee.output.Widget(full_text=self.curprice)
) )
self._curprice = "" self._curprice = ''
self._nextcheck = 0 self._nextcheck = 0
self._interval = int(self.parameter("interval", "120")) self._interval = int(self.parameter('interval', '120'))
self._getbtc = bumblebee.util.asbool(self.parameter("getbtc", True)) self._getbtc = bumblebee.util.asbool(self.parameter('getbtc', True))
self._geteth = bumblebee.util.asbool(self.parameter("geteth", True)) self._geteth = bumblebee.util.asbool(self.parameter('geteth', True))
self._getltc = bumblebee.util.asbool(self.parameter("getltc", True)) self._getltc = bumblebee.util.asbool(self.parameter('getltc', True))
self._getcur = self.parameter("getcur", "usd") self._getcur = self.parameter('getcur', 'usd')
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd="xdg-open https://cryptowat.ch/") cmd='xdg-open https://cryptowat.ch/')
def curprice(self, widget): def curprice(self, widget):
return self._curprice return self._curprice
@ -63,13 +63,13 @@ class Module(bumblebee.engine.Module):
if self._nextcheck < int(time.time()): if self._nextcheck < int(time.time()):
self._nextcheck = int(time.time()) + self._interval self._nextcheck = int(time.time()) + self._interval
currency = self._getcur currency = self._getcur
btcprice, ethprice, ltcprice = "", "", "" btcprice, ethprice, ltcprice = '', '', ''
if self._getbtc: if self._getbtc:
btcprice = getfromkrak('Btc', currency) btcprice = getfromkrak('Btc', currency)
if self._geteth: if self._geteth:
ethprice = getfromkrak('Eth', currency) ethprice = getfromkrak('Eth', currency)
if self._getltc: if self._getltc:
ltcprice = getfromkrak('Ltc', currency) ltcprice = getfromkrak('Ltc', currency)
self._curprice = btcprice+" "*(self._getbtc*self._geteth)+ethprice+" "*(self._getltc*max(self._getbtc, self._geteth))+ltcprice self._curprice = btcprice+' '*(self._getbtc*self._geteth)+ethprice+' '*(self._getltc*max(self._getbtc, self._geteth))+ltcprice
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4