-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate_stats_channel.py
executable file
·41 lines (35 loc) · 1.12 KB
/
create_stats_channel.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
#! /usr/bin/env python
import sys
import urllib.parse
import config
import channel
import slack_token
import slacker
if len(sys.argv) < 2:
print("Usage: {} CHANNELNAME [CHANNELNAME...]".format(sys.argv[0]))
sys.exit(0)
cobj = channel.Channel()
friendlies = cobj.friendly_channel_names()
channels = sys.argv[1:]
creates = []
for c in channels:
if c not in friendlies:
print("Skipping {}: not a real channel".format(c))
else:
creates.append(c)
print("Will create stats channels for {}".format(creates))
slack = slacker.Slacker(config.slack_name, slack_token.token)
for c in creates:
cs = "{}-stats".format(c)
u = "channels.create?name={}".format(cs)
ret = slack.api_call(u)
if ret['ok'] is True:
print("Oh oh: {}".format(ret))
continue
cid = ret['channel']['id']
purpose = "A place to post (and, perhaps, discuss) posting stats to the #{} channel".format(c)
purpose = urllib.parse.quote(purpose)
u = "channels.setPurpose?channel={}&purpose={}".format(cid, purpose)
print("setPurpose: {}".format(u))
ret = slack.api_call(u)
print("ret: {}".format(ret))