[modules/github] Add rudimentary GitHub unread messages module
This commit is contained in:
parent
27f5091ae3
commit
99080e7ac3
1 changed files with 47 additions and 0 deletions
47
bumblebee/modules/github.py
Normal file
47
bumblebee/modules/github.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays the unread github requests of a user
|
||||
|
||||
Requires the following executable:
|
||||
* curl
|
||||
|
||||
Parameters:
|
||||
* github.token: GitHub user access token
|
||||
* github.interval: Interval in minutes
|
||||
"""
|
||||
|
||||
import bumblebee.input
|
||||
import bumblebee.output
|
||||
import bumblebee.engine
|
||||
import re
|
||||
import time
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
super(Module, self).__init__(engine, config,
|
||||
bumblebee.output.Widget(full_text=self.github)
|
||||
)
|
||||
self._count = 0
|
||||
self._interval = int(self.parameter("interval", "5"))
|
||||
self._nextcheck = 0
|
||||
|
||||
def github(self, widget):
|
||||
return self._count
|
||||
|
||||
def update(self, widgets):
|
||||
if self._nextcheck < int(time.time()):
|
||||
self._nextcheck = int(time.time()) + self._interval * 60
|
||||
token = self.parameter("token", "")
|
||||
|
||||
if not token:
|
||||
self._count = 0
|
||||
return
|
||||
|
||||
result = bumblebee.util.execute("curl -s https://api.github.com/notifications\?access_token\=" + token)
|
||||
|
||||
pattern = 'unread'
|
||||
lines = '\n'.join(re.findall(r'^.*%s.*?$'%pattern,result,flags=re.M))
|
||||
|
||||
self._count = len(lines.split('\n'))
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Reference in a new issue