Created
July 17, 2018 11:10
-
-
Save edwardkenfox/e2446029edd2205ee90d91b543aec0e2 to your computer and use it in GitHub Desktop.
slack teamのactiveなアカウントの画像をDLしてくれる君
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
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 |
ネットワークI/O待ちで遅いんで、ちゃんとやるならコネクション張りっぱなしにしてthreadぶん回すのが良さそう
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こんなノリで動くはず