-
Notifications
You must be signed in to change notification settings - Fork 2
/
pushover.py
64 lines (61 loc) · 2.63 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
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
64
import os
import argparse
import requests
def main():
parser = argparse.ArgumentParser(description="Pushover Notifications")
parser.add_argument('--message',
type=str,
help='Message text')
parser.add_argument('--status',
type=str,
help='The current status of the job')
parser.add_argument('--title',
type=str,
help='Message title')
parser.add_argument('--url',
type=str,
help='Supplementary URL to show with your message')
parser.add_argument('--url_title',
type=str,
help='title for your supplementary URL, otherwise just the URL is shown')
parser.add_argument('--device',
type=str,
help='Device name to send the message directly to')
parser.add_argument('--priority',
type=str,
help='Notification priority (low-to-high: -2 to 1)')
parser.add_argument('--sound',
type=str,
help='The name of a supported sound (https://pushover.net/api#sounds; custom sounds are supported)')
args = parser.parse_args()
try:
token = os.environ['PUSHOVER_TOKEN']
user = os.environ['PUSHOVER_USER']
repo = 'Repo: ' + os.environ['GITHUB_REPOSITORY']
sha = 'Commit: ' + os.environ['GITHUB_SHA'][:8]
ref = 'Ref: ' + os.environ['GITHUB_REF'] if 'GITHUB_REF' in os.environ else ''
status = 'Status: ' + args.status if args.status else ''
message = args.message if args.message else ''
message = '\n'.join([m for m in [repo, sha, ref, status, message] if m])
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
payload = {
'token' : token,
'user' : user,
'message' : message,
'title' : args.title,
'url' : args.url,
'url_title' : args.url_title,
'device' : args.device,
'priority' : args.priority,
'sound' : args.sound,
}
response = requests.post('https://api.pushover.net/1/messages.json',
headers=headers,
data=payload,
timeout=60)
response.raise_for_status()
print(response.text)
except requests.exceptions.RequestException as e:
raise e
if __name__ == '__main__':
main()