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 - - diff --git a/README.md b/README.md index 4c6d258..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) @@ -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/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 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/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 diff --git a/bumblebee/modules/stock.py b/bumblebee/modules/stock.py index 6eb4b64..152d624 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,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.currencies : List of symbols to go with the values (default $) """ import bumblebee.input @@ -17,6 +16,7 @@ import bumblebee.output import bumblebee.engine import bumblebee.util +import json import requests import logging @@ -28,36 +28,27 @@ 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._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['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 self._symbols: - url = self._baseurl - url += '?s=%s&f=l1' % self._symbols - if self._change: - url += 'c1' + 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') 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 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 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" },