This repository was archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushnotify.py
More file actions
46 lines (37 loc) · 1.27 KB
/
pushnotify.py
File metadata and controls
46 lines (37 loc) · 1.27 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
39
40
41
42
43
44
45
46
import requests
import logging
logger = logging.getLogger(__name__)
class PushMessage():
"""Send a pushmessage through a Gotify-server.
Prerequisites:
- Gotify server (https://gotify.net/)
- An API-key
@param url: str to a Gotify-server (no trailing slash)
@param key: str to authenticate REST API-call
"""
def __init__(self, url: str, key: str):
self.url = url
self.key = key
def post_msg(self, title: str, message: str, priority: int):
"""
@param title: Title of the push message
@param message: Contents of the push message
@param priority: Integer between 0 and 11. Higher is more
priority for the notification on Android
"""
headers = {
"X-GOTIFY-KEY" : self.key,
"Content-Type" : 'application/json'
}
payload = {
"title" : title,
"message" : message,
"priority" : priority
}
r = requests.post(self.url + "/message", headers=headers, json=payload)
if r.status_code == 200:
logger.debug(r.text)
return True
else:
logger.error(f"Request response: {r.status_code}; {r.text}")
return False