Merge branch 'master' of github.com:tobi-wan-kenobi/bumblebee-status

This commit is contained in:
Tobias Witek 2017-07-29 14:25:59 +02:00
commit 77b962a2f5
3 changed files with 25 additions and 7 deletions

View file

@ -10,8 +10,11 @@ Parameters:
from __future__ import absolute_import from __future__ import absolute_import
import datetime import datetime
import locale
import bumblebee.engine import bumblebee.engine
locale.setlocale(locale.LC_TIME, locale.getdefaultlocale())
ALIASES = [ "date", "time" ] ALIASES = [ "date", "time" ]
def default_format(module): def default_format(module):

View file

@ -29,6 +29,8 @@ class Module(bumblebee.engine.Module):
self._count = 0 self._count = 0
self._interval = int(self.parameter("interval", "5")) self._interval = int(self.parameter("interval", "5"))
self._nextcheck = 0 self._nextcheck = 0
self._requests = requests.Session()
self._requests.headers.update({"Authorization":"token {}".format(self.parameter("token", ""))})
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd="x-www-browser https://github.com/notifications") cmd="x-www-browser https://github.com/notifications")
immediate_update = functools.partial(self.update, immediate=True) immediate_update = functools.partial(self.update, immediate=True)
@ -41,15 +43,19 @@ class Module(bumblebee.engine.Module):
def update(self, _, immediate=False): def update(self, _, immediate=False):
if immediate or self._nextcheck < int(time.time()): if immediate or self._nextcheck < int(time.time()):
self._nextcheck = int(time.time()) + self._interval * 60 self._nextcheck = int(time.time()) + self._interval * 60
token = self.parameter("token", "")
if not token:
self._count = "n/a"
return
try: try:
notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).json() self._count = 0
self._count = len(filter(lambda notification: notification.get("unread", False), notifications)) url = "https://api.github.com/notifications"
while True:
notifications = self._requests.get(url)
self._count += len(filter(lambda notification: notification.get("unread", False), notifications.json()))
next_link = notifications.links.get('next')
if next_link is not None:
url = next_link.get('url')
else:
break
except Exception: except Exception:
self._count = "n/a" self._count = "n/a"

View file

@ -25,6 +25,15 @@ class Module(bumblebee.engine.Module):
) )
self._song = "" self._song = ""
cmd="dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player."
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=cmd + "Previous")
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE,
cmd=cmd + "Next")
engine.input.register_callback(self, button=bumblebee.input.MIDDLE_MOUSE,
cmd=cmd + "PlayPause")
def spotify(self, widget): def spotify(self, widget):
return str(self._song) return str(self._song)