Skip to content

Instantly share code, notes, and snippets.

@edwardkenfox
Created July 17, 2018 11:10
Show Gist options
  • Save edwardkenfox/e2446029edd2205ee90d91b543aec0e2 to your computer and use it in GitHub Desktop.
Save edwardkenfox/e2446029edd2205ee90d91b543aec0e2 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
@edwardkenfox
Copy link
Author

こんなノリで動くはず

$ git clone https://gist.github.com/e2446029edd2205ee90d91b543aec0e2.git
$ mv e2446029edd2205ee90d91b543aec0e2 slack-profile-image-downloader && cd slack-profile-image-downloader
$ echo 'source "https://rubygems.org"\ngem "slack-api"' > Gemfile && bundle
$ mkdir images
$ YOUR_SLACK_APP_OAUTH_TOKEN=XXX bundle exec ruby script.rb

@edwardkenfox
Copy link
Author

ネットワークI/O待ちで遅いんで、ちゃんとやるならコネクション張りっぱなしにしてthreadぶん回すのが良さそう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment