-
Notifications
You must be signed in to change notification settings - Fork 1
/
pushover.py
36 lines (30 loc) · 1.14 KB
/
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
import time
import threading
import http.client
import urllib.parse
class Pushover:
def __init__(self, token: str, user: str):
self.token = token
self.user = user
def _push(self, message: str, priority: int, data: dict) -> None:
if priority == 2:
data = {
"sound": "alien",
"priority": 2,
"retry": 30,
"expire": 3600
}
conn = http.client.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.parse.urlencode({
"token": self.token,
"user": self.user,
"message": message,
"timestamp": time.time(),
"sound": "gamelan"
} | data), {"Content-type": "application/x-www-form-urlencoded"})
conn.getresponse()
def push(self, message: str, priority: int = 0, data: dict = None) -> None:
if data is None:
data = {}
threading.Thread(target=self._push, args=(message, priority, data,)).start()