-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify_slack.py
53 lines (34 loc) · 996 Bytes
/
notify_slack.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
#!/usr/bin/env python
import argparse
from urllib import request, parse
def send(hook_key, message):
url = "https://hooks.slack.com/services/{}".format(hook_key)
data = "payload={'channel': '#scatac', 'username': 'jaeyoung-bot', 'text': '" + \
message + "', 'icon_emoji': ':robot_face:'}"
data = data.encode()
req = request.Request(url, data=data)
response = request.urlopen(req)
print(response.read().decode())
def parse_arguments():
parser = argparse.ArgumentParser(description='notify_slack')
parser.add_argument(
"--hook-key",
action="store",
dest="hook_key",
required=True
)
parser.add_argument(
"--message",
action="store",
dest="message",
required=True
)
# parse arguments
params = parser.parse_args()
return params
if __name__ == "__main__":
params = parse_arguments()
send(
params.hook_key,
params.message
)