-
Notifications
You must be signed in to change notification settings - Fork 1
/
prowl
executable file
·60 lines (48 loc) · 1.72 KB
/
prowl
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
#!/usr/bin/env python3
# Author: github.com/danielhoherd
# License: MIT
"""Send a notification via the Prowlapp.com notification service."""
import platform
import select
import sys
import click
import requests
app = platform.node()
@click.command()
@click.option("--key", "-k", required=True, help="Prowl API key. PROWL_API_KEY", envvar="PROWL_API_KEY")
@click.option("--application", "-a", default=app, help="An application identifier.", show_default=True)
@click.option("--event", "-e", help="An optional name for the event.")
@click.option("--priority", "-p", default=0, help="Priority of the event. (asc pri 0±2)", show_default=True)
@click.argument("description", nargs=-1, required=True)
def send_notification(key, application, event, description, priority):
"""Send a notification via the Prowlapp.com notification service.
Use - to read from stdin."""
if description == tuple("-"):
# select.select() takes no keyword arguments 😭
if select.select(
[
sys.stdin, # rlist
],
[], # wlist
[], # xlist
2.0, # timeout
)[0]:
desc = "".join(list(sys.stdin.readlines()))
else:
desc = ""
else:
desc = " ".join(description)
if not desc:
raise SystemExit("ERROR: No description provided.")
data = {
"apikey": key,
"priority": priority,
"application": application,
"event": event,
"description": desc,
}
response = requests.post("https://api.prowlapp.com/publicapi/add", data=data, timeout=30)
if response.status_code != 200:
raise SystemExit(response.status_code)
if __name__ == "__main__":
send_notification()