[modules/github] Update to latest API
This commit is contained in:
parent
2c4af853a5
commit
0a6f914232
1 changed files with 22 additions and 26 deletions
|
@ -10,39 +10,36 @@ Parameters:
|
||||||
* github.interval: Interval in minutes between updates, default is 5.
|
* github.interval: Interval in minutes between updates, default is 5.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.input
|
import requests
|
||||||
import bumblebee.output
|
|
||||||
import bumblebee.engine
|
|
||||||
|
|
||||||
try:
|
import core.module
|
||||||
import requests
|
import core.widget
|
||||||
except ImportError:
|
import core.decorators
|
||||||
pass
|
import core.input
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, engine, config):
|
@core.decorators.every(minutes=5)
|
||||||
super(Module, self).__init__(engine, config,
|
def __init__(self, config):
|
||||||
bumblebee.output.Widget(full_text=self.github)
|
super().__init__(config, core.widget.Widget(self.github))
|
||||||
)
|
|
||||||
self._count = 0
|
self.__count = 0
|
||||||
self.interval_factor(60)
|
self.__requests = requests.Session()
|
||||||
self.interval(5)
|
self.__requests.headers.update({'Authorization':'token {}'.format(self.parameter('token', ''))})
|
||||||
self._requests = requests.Session()
|
|
||||||
self._requests.headers.update({'Authorization':'token {}'.format(self.parameter('token', ''))})
|
core.input.register(self, button=core.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')
|
||||||
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd=self.update)
|
core.input.register(self, button=core.input.RIGHT_MOUSE, cmd=self.update)
|
||||||
|
|
||||||
def github(self, _):
|
def github(self, _):
|
||||||
return str(self._count)
|
return str(self.__count)
|
||||||
|
|
||||||
def update(self, _):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
self._count = 0
|
self.__count = 0
|
||||||
url = 'https://api.github.com/notifications'
|
url = 'https://api.github.com/notifications'
|
||||||
while True:
|
while True:
|
||||||
notifications = self._requests.get(url)
|
notifications = self.__requests.get(url)
|
||||||
self._count += len(list(filter(lambda notification: notification['unread'], notifications.json())))
|
self.__count += len(list(filter(lambda notification: notification['unread'], notifications.json())))
|
||||||
next_link = notifications.links.get('next')
|
next_link = notifications.links.get('next')
|
||||||
if next_link is not None:
|
if next_link is not None:
|
||||||
url = next_link.get('url')
|
url = next_link.get('url')
|
||||||
|
@ -50,7 +47,6 @@ class Module(bumblebee.engine.Module):
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._count = 'n/a'
|
self.__count = 'n/a'
|
||||||
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue