Created
October 22, 2018 11:15
-
-
Save absynthe/3bd41e6645574e598ad290c6f729066d to your computer and use it in GitHub Desktop.
Iterates over all channels in a slack workspace and builds a dictionary of clientIDs to channel list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import sys | |
| """ | |
| Iterates over all channels in a slack workspace and builds a dictionary of clientIDs to channel list. | |
| """ | |
| member_dictionary = dict() | |
| # get a token from https://api.slack.com/docs/oauth-test-tokens | |
| SLACK_API_TOKEN = "xoxp-..." | |
| all_channels = requests.get('https://slack.com/api/conversations.list?token=%s&exclude_archived=true&limit=1000&types=public_channel,private_channel' % SLACK_API_TOKEN).json()['channels'] | |
| for channel in all_channels: | |
| member_list = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s&limit=500' % (SLACK_API_TOKEN, channel['id'])).json()['members'] | |
| for member in member_list: | |
| if member in member_dictionary.keys(): | |
| member_dictionary[member].append(channel['name']) | |
| else: | |
| member_dictionary[member] = [channel['name']] | |
| for member_id, channel_list in member_dictionary.items(): | |
| print "%s\t%s" % (member_id, ', '.join(channel_list)) | |
| sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment