-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntfy.py
More file actions
63 lines (51 loc) · 1.17 KB
/
ntfy.py
File metadata and controls
63 lines (51 loc) · 1.17 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from typing import Literal, Sequence
import requests
from keys import Keys
tags = Literal[
"+1",
"partying_face",
"tada",
"heavy_check_mark",
"loudspeaker",
"-1",
"warning",
"rotating_light",
"triangular_flag_on_post",
"skull",
"facepalm",
"no_entry",
"no_entry_sign",
"cd",
"computer",
"white_check_mark",
]
def send_ntfy(
*,
title: str,
message: str,
tags: Sequence[tags] | None = None,
priority: int = 0,
) -> requests.Response:
"""
Simple function to send push notifications through ntfy.sh. The topic is private, & hopefully
never compromised. That would be annoying.
Docs: https://docs.ntfy.sh/publish/#message-title
"""
headers = {
"Title": title,
}
if priority:
headers["Priority"] = str(priority)
if tags:
headers["Tags"] = ",".join(tags)
return requests.post(
f"https://ntfy.sh/{Keys.NTFY_TOPIC}",
data=message,
headers=headers,
)
response = send_ntfy(
title="Database limit met",
message="The database has exceeded 90% capacity",
tags=["warning", "white_check_mark"],
priority=5,
)