forked from randsleadershipslack/destalinator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
announcer.py
executable file
·40 lines (30 loc) · 1.17 KB
/
announcer.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
#! /usr/bin/env python
import time
import config
import executor
config = config.Config()
class Announcer(executor.Executor):
def get_new_channels(self):
"""
returns [(channel_name, creator, purpose)] created in the last 24 hours
"""
now = time.time()
dayago = now - 86400
channels = self.slacker.get_all_channel_objects()
new_channels = [channel for channel in channels if channel['created'] > dayago]
new = []
for new_channel in new_channels:
purpose = self.slacker.asciify(new_channel['purpose']['value'])
creator = new_channel['creator']
friendly = self.slacker.asciify(self.slacker.users_by_id[creator])
name = self.slacker.asciify(new_channel['name'])
new.append((name, friendly, purpose))
return new
def announce(self):
new = self.get_new_channels()
for cname, creator, purpose in new:
m = "Channel #{} was created by @{} with purpose: {}".format(cname, creator, purpose)
self.sb.say(config.announce_channel, m)
if __name__ == "__main__":
announcer = Announcer()
announcer.announce()