Skip to content

Instantly share code, notes, and snippets.

@threetreeslight
Forked from edwardkenfox/script.rb
Created August 9, 2019 06:29
Show Gist options
  • Save threetreeslight/8dbfa59eb56403353673a1f0f056d5dd to your computer and use it in GitHub Desktop.
Save threetreeslight/8dbfa59eb56403353673a1f0f056d5dd to your computer and use it in GitHub Desktop.
slack teamのactiveなアカウントの画像をDLしてくれる君
require "slack"
require 'open-uri'
YOUR_SLACK_APP_OAUTH_TOKEN = ENV['YOUR_SLACK_APP_OAUTH_TOKEN']
Slack.configure do |config|
config.token = YOUR_SLACK_APP_OAUTH_TOKEN
end
members = Slack.users_list["members"].select { |m| !m["deleted"] }
members.each.with_index do |member, idx|
puts "=================== #{idx} =======================" if idx % 10 == 0
profile = member["profile"]
url = profile["image_original"]
if url.nil? || url.empty?
url = profile["image_512"]
end
puts url
filename = "#{profile["real_name"]}___#{profile["display_name"]}.png".gsub(" ", "_")
puts filename
begin
file = open(url)
IO.copy_stream(file, "./images/#{filename}")
rescue e
puts "FAILED!!!"
puts "filename: #{filename}"
puts "url: #{url}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment