-
Notifications
You must be signed in to change notification settings - Fork 1
/
notification_pushover.py
executable file
·39 lines (30 loc) · 1.06 KB
/
notification_pushover.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
36
37
38
39
#!/usr/bin/python3
"""Push notifications via Pushover."""
import json
import os
import pathlib
import requests # type: ignore
import exercism
class Notifier: # pylint: disable=R0903
"""Pushover Notifier."""
def __init__(self):
self.pipe = (
pathlib.Path(os.getenv("XDG_RUNTIME_DIR"))
/ "ii" / "localhost" / "#notifications" / "in"
)
config = pathlib.Path(os.getenv("XDG_CONFIG_HOME")) / "pushover" / "user.json"
self.pushover = json.loads(config.read_text())
def notify(self, notification):
"""Push a notification via Pushover."""
msg = notification["text"]
# Write to ii pipe.
self.pipe.write_text(msg + "\n")
# Write to pushover.
data = self.pushover.copy()
data["message"] = msg
url = "https://api.pushover.net/1/messages.json"
requests.post(url, data=data, json=False, timeout=10)
if __name__ == "__main__":
exercism.Exercism.WATCHER_SLEEP_SEC = 200
e = exercism.Exercism()
e.notification_pusher(Notifier().notify)