-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreport_targets.py
executable file
·56 lines (46 loc) · 1.62 KB
/
report_targets.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
#! /usr/bin/env python3
import re
import config
import slacker
import channel
import slack_token
fake = False
slack = slacker.Slacker(config.slack_name, slack_token.token)
channel_obj = channel.Channel()
def users():
"""
return list of users who should get user reports
"""
optchan = config.optin_channel
optchan_id = channel_obj.get(optchan)['slack_cid']
users = slack.get_users_for_channel(optchan_id)
return users
def channels(debug=False):
"""
for a cid that we should get activity for, return
{cid: report_cid} where report_cid is the CID to which we should send the report
"""
friendly_names = channel_obj.friendly_channel_names(active=True)
stats_channels = [x for x in friendly_names if re.match(".*-stats$", x)]
friendly_names = channel_obj.friendly_channel_names()
if debug:
print("Stats channels: {}".format(stats_channels))
# channel_names will be a
# {channel_name_to_do_report_on: channel_name_to_send_report_to}
# dict
channel_names = {}
for stat_channel in stats_channels:
rep = re.sub("-stats$", "", stat_channel)
if rep in friendly_names:
channel_names[rep] = stat_channel
channel_ids = {}
for channel_name in channel_names.keys():
entry = channel_obj.get(channel_name)
if entry:
cid = entry['slack_cid']
report_cid = channel_obj.get(channel_names[channel_name])['slack_cid']
channel_ids[cid] = report_cid
return channel_ids
if __name__ == "__main__":
print("users: {}".format(users()))
print("channels: {}".format(channels(debug=True)))