Merge pull request #123 from fredj/github_module_simplify

[module/github] Use json function from requests and 'filter' instead of a loop
This commit is contained in:
tobi-wan-kenobi 2017-07-07 16:22:07 +02:00 committed by GitHub
commit 1b95f55851

View file

@ -11,7 +11,6 @@ Parameters:
"""
import time
import json
import bumblebee.input
import bumblebee.output
import bumblebee.engine
@ -45,12 +44,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"