-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub_notifications.py
More file actions
38 lines (30 loc) · 1.04 KB
/
github_notifications.py
File metadata and controls
38 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Module to display your Github notifications
"""
from github import Github, GithubException
class Py3status:
cache_timeout = 300
format = " {notifications}"
gh_token = "put your token here"
def _get_notifications(self):
try:
return Github(self.gh_token).get_user().get_notifications().totalCount
except GithubException as github_exception:
print(f"error {github_exception}")
raise
def github_notifications(self):
notifications = self._get_notifications()
full_text = self.py3.safe_format(self.format, {"notifications": notifications})
if notifications and notifications > 0:
color = self.py3.COLOR_BAD
else:
color = self.py3.COLOR_GOOD
return {
"full_text": full_text,
"cached_until": self.py3.time_in(self.cache_timeout),
"color": color,
}
if __name__ == "__main__":
from py3status.module_test import module_test
module_test(Py3status)