From 0ce2a25d4e68ded0b324b77040bcd27713960e4b Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 7 Jul 2017 06:46:10 +0200 Subject: [PATCH] [module/github] Use 'json' from requests and 'filter' instead of a loop --- bumblebee/modules/github.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bumblebee/modules/github.py b/bumblebee/modules/github.py index 2b82a07..2dc4ab9 100644 --- a/bumblebee/modules/github.py +++ b/bumblebee/modules/github.py @@ -11,7 +11,6 @@ Parameters: """ import time -import json import bumblebee.input import bumblebee.output import bumblebee.engine @@ -43,12 +42,8 @@ class Module(bumblebee.engine.Module): return try: - notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).text - unread = 0 - for notification in json.loads(notifications): - if "unread" in notification and notification["unread"]: - unread += 1 - self._count = unread + notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).json() + self._count = len(filter(lambda notification: notification.get("unread", False), notifications)) except Exception: self._count = "n/a"