diff --git a/examples/list.py b/examples/list.py new file mode 100755 index 0000000..18a37df --- /dev/null +++ b/examples/list.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +"""List items in slack.""" + +# https://github.com/os/slacker +# https://api.slack.com/methods + +import os +from slacker import Slacker + + +def list_slack(): + """List channels & users in slack.""" + try: + token = os.environ['SLACK_TOKEN'] + slack = Slacker(token) + + # Get channel list + response = slack.channels.list() + channels = response.body['channels'] + for channel in channels: + print channel['id'], channel['name'] + # if not channel['is_archived']: + # slack.channels.join(channel['name']) + print + + # Get users list + response = slack.users.list() + users = response.body['members'] + for user in users: + if not user['deleted']: + print user['id'], user['name'], user['is_admin'], user[ + 'is_owner'] + print + except KeyError, ex: + print 'Environment variable %s not set.' % str(ex) + + +if __name__ == '__main__': + list_slack() diff --git a/examples/post.py b/examples/post.py new file mode 100755 index 0000000..05b3a0f --- /dev/null +++ b/examples/post.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +"""Post slack message.""" + +# https://github.com/os/slacker +# https://api.slack.com/methods + +import os +from slacker import Slacker + + +def post_slack(): + """Post slack message.""" + try: + token = os.environ['SLACK_TOKEN'] + slack = Slacker(token) + + obj = slack.chat.post_message( + channel='#general', + text='', + as_user=True, + attachments=[{"pretext": "Subject", + "text": "Body"}]) + print obj.successful, obj.__dict__['body']['channel'], obj.__dict__[ + 'body']['ts'] + except KeyError, ex: + print 'Environment variable %s not set.' % str(ex) + + +if __name__ == '__main__': + post_slack()