require "tumblr_client" require 'slack-ruby-client' POST_DELAY = 30.minutes SLACK_CHANNEL = '#nsfw' # bonjourmademoiselle.fr dites.bonjourmadame.fr bonjourlesfesses.tumblr.com TUMBLR_SOURCE = 'bonjourmademoiselle.fr' PAGE_LENGTH = 20 the_end = false offset = 0 Slack.configure do |config| config.token = ENV['SLACK_API_TOKEN'] end # Authenticate via API Key client = Tumblr::Client.new :consumer_key => ENV['TUMBLR_API_TOKEN'] # On s'auth sur slack slack_client = Slack::Web::Client.new slack_client.auth_test # On fetch tous les posts while !the_end do posts = client.posts TUMBLR_SOURCE, offset: offset images = posts["posts"].map{|p| p["photos"].map{|e| [p["summary"], e["original_size"]["url"]]}.to_h }.flatten offset += PAGE_LENGTH the_end = true if posts["posts"].count < PAGE_LENGTH # Et on balance une image toutes les {POST_DELAY} 👌 images.flatten.map{|e| [e.keys.first, e.values]}.to_h.each do |caption, urls| slack_client.chat_postMessage(channel: SLACK_CHANNEL, text: "#{caption}: #{urls.join(', ')}", as_user: true) sleep(POST_DELAY) end end