[module/github] Use 'json' from requests and 'filter' instead of a loop
This commit is contained in:
parent
8fb100c237
commit
0ce2a25d4e
1 changed files with 2 additions and 7 deletions
|
@ -11,7 +11,6 @@ Parameters:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
import bumblebee.output
|
import bumblebee.output
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
|
@ -43,12 +42,8 @@ class Module(bumblebee.engine.Module):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).text
|
notifications = requests.get("https://api.github.com/notifications", headers={"Authorization":"token {}".format(token)}).json()
|
||||||
unread = 0
|
self._count = len(filter(lambda notification: notification.get("unread", False), notifications))
|
||||||
for notification in json.loads(notifications):
|
|
||||||
if "unread" in notification and notification["unread"]:
|
|
||||||
unread += 1
|
|
||||||
self._count = unread
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._count = "n/a"
|
self._count = "n/a"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue