To make a roulette to choose one person for the closing party, I took a photo of all the employees from Slack.
Let's get the URL of the user's icon with the API.
https://slack.com/api/users.list?token=xoxb-12345678-12345679-thairoo1airi6om7Ahga
In this way, you need to issue a valid token to get the information of all users in json.
If you don't have the token, go to https://api.slack.com/apps/
"Create New App", select "Permission" after creating with a name, "User Token Scopes"
Set ʻusers.read. When you press install, a token starting with
xoxb` will be issued. This was detailed with an image.
Once you have a valid token ready, you can download it with the following python script. Click here for the repository (gist).
download-slack-profile-pictures.py
import requests
import time
TOKEN = "xoxb-12345678-12345679-thairoo1airi6om7Ahga"
def main():
url = "https://slack.com/api/users.list?token=" + TOKEN
response = requests.get(url)
response.raise_for_status()
for i, member in enumerate(response.json()['members']):
image512px_url = member['profile']['image_512']
print(i + 1, image512px_url)
response = requests.get(image512px_url)
response.raise_for_status()
filename = f"./{member['team_id']}-{member['id']}-{member['name']}.jpg "
with open(filename, 'wb') as f:
f.write(response.content)
time.sleep(1)
if __name__ == '__main__':
main()
Recommended Posts