-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (31 loc) · 1.33 KB
/
main.py
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
#!/usr/bin/env python3.8
import secrets
import requests
import subprocess
endpoint = "https://api.github.com/notifications"
headers = {"Authorization": "token "+secrets.token,
"Accept": "application/vnd.github.v3+json"}
params = {"all": "false"} # only unread notifications
icon = "--icon=/home/miguel/dev/notification-baby-monitor/github_icon_32px.png"
expire = "--expire-time=20000"
raw_response = requests.get(endpoint, headers=headers, params=params)
if raw_response.status_code == requests.codes.ok:
response = raw_response.json()
n_notifications = len(response)
notification_titles = []
if n_notifications > 0:
if n_notifications == 1:
title = "There is a new notification:"
else:
title = "There are " + str(n_notifications) + " new notifications:"
for notification in response:
notification_titles.append(
" • [" + notification["repository"]["name"] + "] " + notification["subject"]["title"])
arguments = ["/usr/bin/notify-send", expire, icon,
title, "\n".join(notification_titles)]
subprocess.Popen(arguments)
else:
arguments = ["/usr/bin/notify-send", expire, icon, "Everything clear!"]
subprocess.Popen(arguments)
else:
print("Request returned code" + raw_response.status_code)