From f1410b7c1fce8afb579e3b9762e298c0f96ec541 Mon Sep 17 00:00:00 2001 From: WORD559 Date: Thu, 3 Oct 2019 16:36:26 +0100 Subject: [PATCH 1/9] Use util.asbool rather than manual true-value parsing --- bumblebee/output.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bumblebee/output.py b/bumblebee/output.py index f70b605..004dfe8 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -7,15 +7,14 @@ import json import uuid import bumblebee.store - -_TrueValues = ["true", "t", "yes", "y", "1"] +import bumblebee.util def scrollable(func): def wrapper(module, widget): text = func(module, widget) if not text: return text width = widget.get("theme.width", module.parameter("width", 30)) - if module.parameter("scrolling.makewide", "true").lower() in _TrueValues: + if bumblebee.util.asbool(module.parameter("scrolling.makewide", "true")): widget.set("theme.minwidth", "A"*width) if len(text) <= width: return text From fb2fb796da4c9f7ab840578d133f7800702e84ed Mon Sep 17 00:00:00 2001 From: WORD559 Date: Fri, 4 Oct 2019 15:18:11 +0100 Subject: [PATCH 2/9] add test for asbool --- tests/test_util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 07d6d3a..828728b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -69,5 +69,15 @@ class TestUtil(unittest.TestCase): # test if which also works with garbage input self.assertTrue(bu.which("qwertygarbage") is None) + def test_asbool(self): + for val in ("t", "true", "y", "yes", "on", "1", 1, True): + self.assertTrue(bu.asbool(val)) + if isinstance(val, str): + self.assertTrue(bu.asbool(val.upper())) + + for val in ("f", "false", "n", "no", "off", "0", 0, False): + self.assertFalse(bu.asbool(val)) + if isinstance(val, str): + self.assertFalse(bu.asbool(val.upper())) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From ac088433865e19c9dfa0317b0c26172192d8e6ee Mon Sep 17 00:00:00 2001 From: William Wagner Moraes Artero Date: Fri, 11 Oct 2019 15:10:25 -0300 Subject: [PATCH 3/9] [module] deezer --- README.md | 2 +- bumblebee/modules/deezer.py | 77 +++++++++++++++++++++++++++++++++ themes/icons/ascii.json | 3 ++ themes/icons/awesome-fonts.json | 3 ++ themes/icons/ionicons.json | 3 ++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 bumblebee/modules/deezer.py diff --git a/README.md b/README.md index 4c6d258..42b84e2 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Modules and commandline utilities are only required for modules, the core itself * netifaces (for the modules 'nic', 'traffic') * requests (for the modules 'weather', 'github', 'getcrypto', 'stock', 'currency', 'sun') * power (for the module 'battery') -* dbus (for the module 'spotify') +* dbus (for the module 'spotify', 'deezer') * i3ipc (for the module 'title') * pacman-contrib (for module 'arch-update') * docker (for the module 'docker_ps') diff --git a/bumblebee/modules/deezer.py b/bumblebee/modules/deezer.py new file mode 100644 index 0000000..582c7fc --- /dev/null +++ b/bumblebee/modules/deezer.py @@ -0,0 +1,77 @@ +# pylint: disable=C0111,R0903 + +"""Displays the current song being played +Requires the following library: + * python-dbus +Parameters: + * deezer.format: Format string (defaults to "{artist} - {title}") + Available values are: {album}, {title}, {artist}, {trackNumber}, {playbackStatus} + * deezer.previous: Change binding for previous song (default is left click) + * deezer.next: Change binding for next song (default is right click) + * deezer.pause: Change binding for toggling pause (default is middle click) + Available options for deezer.previous, deezer.next and deezer.pause are: + LEFT_CLICK, RIGHT_CLICK, MIDDLE_CLICK, SCROLL_UP, SCROLL_DOWN +""" + +import bumblebee.input +import bumblebee.output +import bumblebee.engine + +from bumblebee.output import scrollable + +try: + import dbus +except ImportError: + pass + + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.deezer) + ) + buttons = {"LEFT_CLICK":bumblebee.input.LEFT_MOUSE, + "RIGHT_CLICK":bumblebee.input.RIGHT_MOUSE, + "MIDDLE_CLICK":bumblebee.input.MIDDLE_MOUSE, + "SCROLL_UP":bumblebee.input.WHEEL_UP, + "SCROLL_DOWN":bumblebee.input.WHEEL_DOWN, + } + + self._song = "" + self._format = self.parameter("format", "{artist} - {title}") + prev_button = self.parameter("previous", "LEFT_CLICK") + next_button = self.parameter("next", "RIGHT_CLICK") + pause_button = self.parameter("pause", "MIDDLE_CLICK") + + cmd = "dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.deezer \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." + engine.input.register_callback(self, button=buttons[prev_button], + cmd=cmd + "Previous") + engine.input.register_callback(self, button=buttons[next_button], + cmd=cmd + "Next") + engine.input.register_callback(self, button=buttons[pause_button], + cmd=cmd + "PlayPause") + +## @scrollable + def deezer(self, widget): + return str(self._song) + + def hidden(self): + return str(self._song) == "" + + def update(self, widgets): + try: + bus = dbus.SessionBus() + deezer = bus.get_object("org.mpris.MediaPlayer2.deezer", "/org/mpris/MediaPlayer2") + deezer_iface = dbus.Interface(deezer, 'org.freedesktop.DBus.Properties') + props = deezer_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata') + playback_status = str(deezer_iface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')) + self._song = self._format.format(album=str(props.get('xesam:album')), + title=str(props.get('xesam:title')), + artist=','.join(props.get('xesam:artist')), + trackNumber=str(props.get('xesam:trackNumber')), + playbackStatus=u"\u25B6" if playback_status=="Playing" else u"\u258D\u258D" if playback_status=="Paused" else "",) + except Exception: + self._song = "" + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 3b24f47..fc36b95 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -247,6 +247,9 @@ "github": { "prefix": "github" }, + "deezer": { + "prefix": "" + }, "spotify": { "prefix": "" }, diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index d5e947f..476d065 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -172,6 +172,9 @@ "github": { "prefix": "  " }, + "deezer": { + "prefix": "  " + }, "spotify": { "prefix": "  " }, diff --git a/themes/icons/ionicons.json b/themes/icons/ionicons.json index 9f7a116..cf7813a 100644 --- a/themes/icons/ionicons.json +++ b/themes/icons/ionicons.json @@ -153,6 +153,9 @@ "github": { "prefix": "\uf233" }, + "deezer": { + "prefix": "\uf305" + }, "spotify": { "prefix": "\uf305" }, From 80b76e991cd3e5a66de20c2540e659031fad0d62 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 11 Oct 2019 20:36:44 +0200 Subject: [PATCH 4/9] [doc] Bump module count (deezer) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42b84e2..9095682 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Test Coverage](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/coverage.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/coverage) [![Issue Count](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/issue_count.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status) -**Many, many thanks to all contributors! As of now, 48 of the modules are from various contributors (!), and only 19 from myself.** +**Many, many thanks to all contributors! As of now, 49 of the modules are from various contributors (!), and only 19 from myself.** ![Solarized Powerline](https://github.com/tobi-wan-kenobi/bumblebee-status/blob/master/screenshots/themes/powerline-solarized.png) From 4a2835550752e90f12bc33d37e88562c8b4b8cef Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 12 Oct 2019 15:11:45 +0200 Subject: [PATCH 5/9] Update issue templates --- .github/ISSUE_TEMPLATE/Bug.md | 16 +++++++--------- .github/ISSUE_TEMPLATE/Feature.md | 4 ++++ .github/ISSUE_TEMPLATE/Support.md | 20 -------------------- 3 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/Support.md diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md index 4147989..9166876 100644 --- a/.github/ISSUE_TEMPLATE/Bug.md +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -1,6 +1,10 @@ --- -name: Bug Report -about: Something is broken / doesn't work as expected +name: Bug Report +about: Something doesn't work (as expected) +title: '' +labels: '' +assignees: '' + --- ### Bug Report @@ -8,17 +12,12 @@ about: Something is broken / doesn't work as expected #### Summary Affected module: -Description: +#### Description: -#### What is the current behaviour and what is the expected behaviour? - #### How to reproduce -#### Expected behavior - - - diff --git a/.github/ISSUE_TEMPLATE/Feature.md b/.github/ISSUE_TEMPLATE/Feature.md index fcc2335..4b795ad 100644 --- a/.github/ISSUE_TEMPLATE/Feature.md +++ b/.github/ISSUE_TEMPLATE/Feature.md @@ -1,6 +1,10 @@ --- name: Feature Request about: You have a neat idea that should be implemented? +title: '' +labels: '' +assignees: '' + --- ### Feature Request diff --git a/.github/ISSUE_TEMPLATE/Support.md b/.github/ISSUE_TEMPLATE/Support.md deleted file mode 100644 index e3802f8..0000000 --- a/.github/ISSUE_TEMPLATE/Support.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: ❓ Support Question -about: Have a problem that you can't figure out? ---- - - - - -| Q | A -|------------ | ----- -| Version | x - - -#### Support Question - - From e1f8ed68062799511df6efe549054054ad2ab184 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 14 Oct 2019 20:44:28 +0200 Subject: [PATCH 6/9] [modules/stock] Use www.worldtradingdata.com Since yahoo.com doesn't seem to offer a free API anymore, use www.worldtradingdata.com instead. NOTE: This needs an API token! --- bumblebee/modules/stock.py | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/bumblebee/modules/stock.py b/bumblebee/modules/stock.py index 6eb4b64..9504b77 100644 --- a/bumblebee/modules/stock.py +++ b/bumblebee/modules/stock.py @@ -1,7 +1,7 @@ # -*- coding: UTF-8 -*- # pylint: disable=C0111,R0903 -"""Display a stock quote from yahoo finance. +"""Display a stock quote from worldtradingdata.com Requires the following python packages: * requests @@ -9,7 +9,7 @@ Requires the following python packages: Parameters: * stock.symbols : Comma-separated list of symbols to fetch * stock.change : Should we fetch change in stock value (defaults to True) - * stock.currencies : List of symbols to go with the values (default $) + * stock.token : Your API token registered at https://worldtradingdata.com """ import bumblebee.input @@ -17,6 +17,7 @@ import bumblebee.output import bumblebee.engine import bumblebee.util +import json import requests import logging @@ -28,36 +29,29 @@ class Module(bumblebee.engine.Module): ) self._symbols = self.parameter('symbols', '') self._change = bumblebee.util.asbool(self.parameter('change', True)) - self._currencies = self.parameter('currencies', None) - self._baseurl = 'http://download.finance.yahoo.com/d/quotes.csv' - self._value = self.fetch() + self._token = self.parameter('token', None) + self._value = None self.interval(60) - if not self._currencies: - self._currencies = '$' * len(self._symbols) - - # The currencies could be unicode, like the € symbol. Convert to a unicode object. - if hasattr(self._currencies, 'decode'): - self._currencies = self._currencies.decode('utf-8', 'ignore') - def value(self, widget): results = [] if not self._value: return 'n/a' - for i, val in enumerate(self._value.split('\n')): - try: - currency_symbol = self._currencies[i] - except: - currency_symbol = '$' - results.append('%s%s' % (currency_symbol, val)) + data = json.loads(self._value) + + for symbol in data['data']: + val = 'day_change' if self._change else 'price' + results.append('{} {}{}'.format(symbol['symbol'], symbol[val], symbol['currency'])) return u' '.join(results) def fetch(self): + if not self._token: + logging.error('please specify a token') + return None if self._symbols: - url = self._baseurl - url += '?s=%s&f=l1' % self._symbols - if self._change: - url += 'c1' + url = 'https://api.worldtradingdata.com/api/v1/stock?' + url += 'api_token={}'.format(self._token) + url += '&symbol={}'.format(self._symbols) return requests.get(url).text.strip() else: logging.error('unable to retrieve stock exchange rate') From e6d36ffd965763abf6980113a2bface4e0046c99 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 14 Oct 2019 21:19:39 +0200 Subject: [PATCH 7/9] [modules/stock] Revert to using stock API Many thanks to @mschwartz for pointing out how to! see #453 --- bumblebee/modules/stock.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/bumblebee/modules/stock.py b/bumblebee/modules/stock.py index 9504b77..152d624 100644 --- a/bumblebee/modules/stock.py +++ b/bumblebee/modules/stock.py @@ -9,7 +9,6 @@ Requires the following python packages: Parameters: * stock.symbols : Comma-separated list of symbols to fetch * stock.change : Should we fetch change in stock value (defaults to True) - * stock.token : Your API token registered at https://worldtradingdata.com """ import bumblebee.input @@ -29,7 +28,6 @@ class Module(bumblebee.engine.Module): ) self._symbols = self.parameter('symbols', '') self._change = bumblebee.util.asbool(self.parameter('change', True)) - self._token = self.parameter('token', None) self._value = None self.interval(60) @@ -39,19 +37,18 @@ class Module(bumblebee.engine.Module): return 'n/a' data = json.loads(self._value) - for symbol in data['data']: - val = 'day_change' if self._change else 'price' - results.append('{} {}{}'.format(symbol['symbol'], symbol[val], symbol['currency'])) + for symbol in data['quoteResponse']['result']: + valkey = 'regularMarketChange' if self._change else 'regularMarketPrice' + sym = 'n/a' if not 'symbol' in symbol else symbol['symbol'] + currency = 'USD' if not 'currency' in symbol else symbol['currency'] + val = 'n/a' if not valkey in symbol else '{:.2f}'.format(symbol[valkey]) + results.append('{} {} {}'.format(sym, val, currency)) return u' '.join(results) def fetch(self): - if not self._token: - logging.error('please specify a token') - return None if self._symbols: - url = 'https://api.worldtradingdata.com/api/v1/stock?' - url += 'api_token={}'.format(self._token) - url += '&symbol={}'.format(self._symbols) + url = 'https://query1.finance.yahoo.com/v7/finance/quote?symbols=' + url += self._symbols + '&fields=regularMarketPrice,currency,regularMarketChange' return requests.get(url).text.strip() else: logging.error('unable to retrieve stock exchange rate') From cc58817978e4806c29c19cbe2e163909dd6c3b1f Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 20 Oct 2019 09:58:12 +0200 Subject: [PATCH 8/9] [modules/battery_all] Better error handling if battery not found When there are errors identifying the battery, make sure that the module returns "n/a" instead of just throwing an error. fixes #455 --- bumblebee/modules/battery_all.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bumblebee/modules/battery_all.py b/bumblebee/modules/battery_all.py index 8f4cebc..52849bd 100644 --- a/bumblebee/modules/battery_all.py +++ b/bumblebee/modules/battery_all.py @@ -25,9 +25,12 @@ except ImportError: class Module(bumblebee.engine.Module): def __init__(self, engine, config): self._batteries = [] - for battery in os.listdir('/sys/class/power_supply/'): - if not any(i in battery for i in ['AC', 'hidpp']): - self._batteries.append("/sys/class/power_supply/" + battery) + try: + for battery in os.listdir('/sys/class/power_supply/'): + if not any(i in battery for i in ['AC', 'hidpp']): + self._batteries.append("/sys/class/power_supply/" + battery) + except: + pass super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity)) @@ -67,11 +70,7 @@ class Module(bumblebee.engine.Module): errors += 1 if errors == len(self._batteries): - # if all batteries return errors, but we are still running - # assume we are on A/C - widget.set("ac", True) - widget.set("capacity", 100) - return "ac" + return "n/a" capacity = int( float(self.energy_now) / float(self.energy_full) * 100.0) capacity = capacity if capacity < 100 else 100 From 0f53567f3172e5d0e96e14776fcc71e42097d9b5 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 20 Oct 2019 10:07:44 +0200 Subject: [PATCH 9/9] [modules/sensors(2)] Better (?) CPU reading Add support for ARM/PowerPC (BogoMIPS) and make sure that the module doesn't throw errors when problems reading the CPU frequency occurs. fixes #458 --- bumblebee/modules/sensors.py | 10 +++++++++- bumblebee/modules/sensors2.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/sensors.py b/bumblebee/modules/sensors.py index 92f3feb..567d9db 100644 --- a/bumblebee/modules/sensors.py +++ b/bumblebee/modules/sensors.py @@ -93,13 +93,21 @@ class Module(bumblebee.engine.Module): return temperature def get_mhz(self): + mhz = None try: output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() mhz = int(float(output)/1000.0) except: output = open("/proc/cpuinfo").read() m = re.search(r"cpu MHz\s+:\s+(\d+)", output) - mhz = int(m.group(1)) + if m: + mhz = int(m.group(1)) + else: + m = re.search(r"BogoMIPS\s+:\s+(\d+)", output) + if m: + return "{} BogoMIPS".format(int(m.group(1))) + if not mhz: + return "n/a" if mhz < 1000: return "{} MHz".format(mhz) diff --git a/bumblebee/modules/sensors2.py b/bumblebee/modules/sensors2.py index eee997f..3bd245a 100644 --- a/bumblebee/modules/sensors2.py +++ b/bumblebee/modules/sensors2.py @@ -132,18 +132,25 @@ class Module(bumblebee.engine.Module): return output def _cpu(self, _): + mhz = None try: output = open("/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq").read() mhz = int(float(output)/1000.0) except: output = open("/proc/cpuinfo").read() m = re.search(r"cpu MHz\s+:\s+(\d+)", output) - mhz = int(m.group(1)) + if m: + mhz = int(m.group(1)) + else: + m = re.search(r"BogoMIPS\s+:\s+(\d+)", output) + if m: + return "{} BogoMIPS".format(int(m.group(1))) + if not mhz: + return "n/a" if mhz < 1000: return "{} MHz".format(mhz) else: return "{:0.01f} GHz".format(float(mhz)/1000.0) - # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4