From 99080e7ac3bb1d02993a71232ebadebf4f673118 Mon Sep 17 00:00:00 2001 From: Yves Hoppe Date: Fri, 26 May 2017 11:06:20 +0200 Subject: [PATCH 1/4] [modules/github] Add rudimentary GitHub unread messages module --- bumblebee/modules/github.py | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bumblebee/modules/github.py diff --git a/bumblebee/modules/github.py b/bumblebee/modules/github.py new file mode 100644 index 0000000..a558f34 --- /dev/null +++ b/bumblebee/modules/github.py @@ -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 From 320b4b466ef0c9fe9992fdba8d425a47fe5dcef8 Mon Sep 17 00:00:00 2001 From: Yves Hoppe Date: Fri, 26 May 2017 11:11:58 +0200 Subject: [PATCH 2/4] Plugin description --- bumblebee/modules/github.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/github.py b/bumblebee/modules/github.py index a558f34..7e0412c 100644 --- a/bumblebee/modules/github.py +++ b/bumblebee/modules/github.py @@ -1,6 +1,6 @@ # pylint: disable=C0111,R0903 -"""Displays the unread github requests of a user +"""Displays the unread GitHub notifications for a GitHub user Requires the following executable: * curl From 710342d7d417212e777e29e06e667a0a9fa78d4f Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 26 May 2017 13:32:47 +0200 Subject: [PATCH 3/4] [modules/github] Minor refactoring * Use requests library instead of curl * Exactly parse the github API responses * Return a string value in order to pass unit tests see #86 --- bumblebee/modules/github.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bumblebee/modules/github.py b/bumblebee/modules/github.py index 7e0412c..187d266 100644 --- a/bumblebee/modules/github.py +++ b/bumblebee/modules/github.py @@ -15,6 +15,13 @@ import bumblebee.output import bumblebee.engine import re import time +import json + +try: + import requests + from requests.exceptions import RequestException +except ImportError: + pass class Module(bumblebee.engine.Module): def __init__(self, engine, config): @@ -26,7 +33,7 @@ class Module(bumblebee.engine.Module): self._nextcheck = 0 def github(self, widget): - return self._count + return str(self._count) def update(self, widgets): if self._nextcheck < int(time.time()): @@ -37,11 +44,11 @@ class Module(bumblebee.engine.Module): 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')) + notifications = requests.get("https://api.github.com/notifications?access_token={}".format(token)).text + unread = 0 + for notification in json.loads(notifications): + if "unread" in notification and notification["unread"] == True: + unread += 1 + self._count = unread # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From 6c6434cefd0836e98136ce2083615fe63a961c6e Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 26 May 2017 16:32:38 +0200 Subject: [PATCH 4/4] [screenshots] Added github module screenshot --- screenshots/github.png | Bin 0 -> 853 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 screenshots/github.png diff --git a/screenshots/github.png b/screenshots/github.png new file mode 100644 index 0000000000000000000000000000000000000000..bbcf48bf9b8c3a8b7212633c04d0282fed8f3c0f GIT binary patch literal 853 zcmV-b1FHOqP)>XWx9xTpwmx92+OiiDD(7wXoPXvwbN)LsBGA+Z_G?HkpSH7CJbdXW4oW@= z1om-ASaMri+rCh!7!VS19f}HoV;E)vn^nl9drbyGP>-!CNoES93JS6SINhF5G`81d zA^9kfu9fuu% zAFPHVQ=WN2eQC3rX_|gI@g7g6o=;Axl!|tnnNwAZYL1)hIU1r;%7SK-fn9Oa3Cpc9^I_;Ro=&kMD3Qn~iYSdRj zdH;yAr`g8oiC-~2w*UYbaX5E|hZ_#gE-dpA#&BX{2HVZ$A6yHMM&A{Hs6@)TtY(o& z#AgoYj5|RPm(JQN%aQ)>w%RJqn`sx%g@t2@NtY*^&E}`@Bl=tl8N&&d2^c1ed3~*xhJlkEVhFl7G8)H|{9Un`N@XZYTcM8O1fo*%eU+GW)ftLP zk|cM7Hu2k!NB;SG_4?POFszWt_+I=w(PYpYwN*v9{%4n#7Xv|IZ~%acva;elde;*P f!EpaK_BGrORhSM^q*P_%00000NkvXXu0mjf;2(f_ literal 0 HcmV?d00001