Skip to content

Commit

Permalink
Merge pull request #334 from adinhodovic/add-github
Browse files Browse the repository at this point in the history
Add GitHub notifications block
  • Loading branch information
denisse-dev authored May 25, 2021
2 parents 6ef2254 + f5e2f56 commit 30281f6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
22 changes: 22 additions & 0 deletions github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Github

Shows Github notifications and adds a shortcut to access your notifications. It uses [Github's CLI](https://github.com/cli/cli) for api interactions and for an API access.

# Dependencies

- [gh-cli](https://github.com/cli/cli)
- [Font Awesome](https://fontawesome.com) for the Github icon.

# Usage

Clicking the Github icon will open Github's notifications panel.

# Config

```ini
[github]
command=$SCRIPT_DIR/github/github
interval=60
format=json
markup=pango
```
35 changes: 35 additions & 0 deletions github/github
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
A Github block for displaying notifications in i3 using i3blocks
"""

__author__ = "Adin Hodovic <hodovicadin@gmail.com>"
__copyright__ = "Copyright (c) 2020 Adin Hodovic"
__license__ = "MIT"
__version__ = "1.0.0"

import json
import os
import webbrowser


def get_notifications():
notifications = len(json.loads(os.popen("gh api notifications").read()))

if notifications > 0:
return {
"full_text": f"<span font='Font Awesome 5 Free Solid'>&#xf09b; {notifications}</span>"
}
return {"full_text": "<span font='Font Awesome 5 Free Solid'>&#xf09b;</span>"}


def clicked():
"""Returns True if the button was clicked"""
button = "BLOCK_BUTTON" in os.environ and os.environ["BLOCK_BUTTON"]
return bool(button)


if clicked():
webbrowser.open("https://github.com/notifications")

print(json.dumps(get_notifications()))
5 changes: 5 additions & 0 deletions github/i3blocks.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[github]
command=$SCRIPT_DIR/github/github
interval=60
format=json
markup=pango

0 comments on commit 30281f6

Please sign in to comment.