From 2d3b153f0c3ec7fd808bd79b832bda9b370abeb4 Mon Sep 17 00:00:00 2001 From: Ryunaq Date: Wed, 14 Jun 2017 11:26:04 -0500 Subject: [PATCH 1/4] [modules/getcrypto] Get crypto prices module A module for getting the prices of BTC, ETH and/or LTC from Kraken. --- bumblebee/modules/getcrypto.py | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bumblebee/modules/getcrypto.py diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py new file mode 100644 index 0000000..d87bef0 --- /dev/null +++ b/bumblebee/modules/getcrypto.py @@ -0,0 +1,66 @@ +# pylint: disable=C0111,R0903 + +"""Displays the price of a cryptocurrency. + +Requires the following python packages: + * requests + +Parameters: + * getcrypto.interval: Interval in seconds for updating the price, default is 60, less than that will get your IP banned. + * 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). +""" + +import requests +import time +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +def getfromkrak(coin): + if coin=='Btc': + epair = "xbtusd" + tickname = "XXBTZUSD" + if coin=='Eth': + epair = "ethusd" + tickname = "XETHZUSD" + if coin=='Ltc': + epair = "ltcusd" + tickname = "XLTCZUSD" + krakenget = requests.get('https://api.kraken.com/0/public/Ticker?pair='+epair).json() + kethusdask = float(krakenget['result'][tickname]['a'][0]) + kethusdbid = float(krakenget['result'][tickname]['b'][0]) + return coin+": "+str((kethusdask+kethusdbid)/2)[0:6] + + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.curprice) + ) + self._curprice = 0 + self._nextcheck = 0 + self._interval = int(self.parameter("interval", "120")) + self._getbtc = int(self.parameter("getbtc", "1")) + self._geteth = int(self.parameter("geteth", "1")) + self._getltc = int(self.parameter("getltc", "1")) + #engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, + # cmd="gnome-system-monitor") + + def curprice(self, widget): + return self._curprice + + def update(self, widgets): + if self._nextcheck < int(time.time()): + self._nextcheck = int(time.time()) + self._interval + btcprice, ethprice, ltcprice = "", "", "" + if self._getbtc==1: + btcprice= getfromkrak('Btc') + if self._geteth==1: + ethprice=getfromkrak('Eth') + if self._getltc==1: + ltcprice=getfromkrak('Ltc') + self._curprice = btcprice+" "*(self._getbtc*self._geteth)+ethprice+" "*(self._getltc*max(self._getbtc, self._geteth))+ltcprice + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 8d842eb04314eede6eb06f0b26e66399cfac7dd1 Mon Sep 17 00:00:00 2001 From: Ryunaq Date: Wed, 14 Jun 2017 11:30:48 -0500 Subject: [PATCH 2/4] [modules/getcrypto] Get crypto prices module Extremely niche module that will probably never be used for getting the price of BTC, ETH and/or LTC from Kraken. --- bumblebee/modules/getcrypto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index d87bef0..f0aab90 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -6,7 +6,7 @@ Requires the following python packages: * requests Parameters: - * getcrypto.interval: Interval in seconds for updating the price, default is 60, less than that will get your IP banned. + * getcrypto.interval: Interval in seconds for updating the price, default is 120, less than that will probably get your IP banned. * 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). From 82af91f7372a90bf46200b7661d292dc63ff5b69 Mon Sep 17 00:00:00 2001 From: Fernando Chu Date: Wed, 14 Jun 2017 12:00:51 -0500 Subject: [PATCH 3/4] Forgot to change the left-click interaction --- bumblebee/modules/getcrypto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index f0aab90..f2f20eb 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -45,8 +45,8 @@ 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")) - #engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, - # cmd="gnome-system-monitor") + engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, + cmd="xdg-open https://cryptowat.ch/") def curprice(self, widget): return self._curprice From f635bed4d09106366b1d321e9614866e05c7b791 Mon Sep 17 00:00:00 2001 From: Fernando Chu Date: Wed, 14 Jun 2017 14:31:31 -0500 Subject: [PATCH 4/4] Changed _curprice to string --- bumblebee/modules/getcrypto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/getcrypto.py b/bumblebee/modules/getcrypto.py index f2f20eb..1f0aed7 100644 --- a/bumblebee/modules/getcrypto.py +++ b/bumblebee/modules/getcrypto.py @@ -39,7 +39,7 @@ class Module(bumblebee.engine.Module): super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.curprice) ) - self._curprice = 0 + self._curprice = "" self._nextcheck = 0 self._interval = int(self.parameter("interval", "120")) self._getbtc = int(self.parameter("getbtc", "1"))