[modules] weather & github: Protect against missing data

If data cannot be retrieved for some reason (be pretty generous about
that by catching generic exceptions), instead of terminating the whole
status bar, simply report unknown data.

see #110
This commit is contained in:
Tobias Witek 2017-06-10 13:59:44 +02:00
parent b89e384b20
commit dc06611fb1
2 changed files with 10 additions and 4 deletions

View file

@ -44,9 +44,13 @@ class Module(bumblebee.engine.Module):
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
try:
for notification in json.loads(notifications):
if "unread" in notification and notification["unread"]:
unread += 1
self._count = unread
except Exception:
self._count = "n/a"
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -70,5 +70,7 @@ class Module(bumblebee.engine.Module):
self._valid = True
except RequestException:
self._valid = False
except Exception:
self._valid = False
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4