Created
September 18, 2018 22:48
-
-
Save rummanwaqar/03bba7e2eaa92775938438a4fc64cb2e to your computer and use it in GitHub Desktop.
Retrieves emails for all users in a slack channel
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
''' | |
pip install slackclient | |
You can generate or find your personal Slack token here: https://api.slack.com/custom-integrations/legacy-tokens | |
''' | |
import sys | |
from slackclient import SlackClient | |
if len(sys.argv) != 3: | |
print('Usage: python slack_emails.py token channel') | |
exit(1) | |
auth_token = sys.argv[1] | |
specific_channel = sys.argv[2] | |
sc = SlackClient(auth_token) | |
members = None | |
for channel in sc.api_call('channels.list')['channels']: | |
if channel['name'] == specific_channel: | |
members = channel['members'] | |
if not members: | |
print('No members for channel {}'.format(specific_channel)) | |
exit(1) | |
else: | |
for member in members: | |
print(sc.api_call('users.info', user=member)['user']['profile']['email']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment