Skip to content

Instantly share code, notes, and snippets.

@daybreaker
Last active April 10, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daybreaker/42c3626356fb7cd24b5883800b2b583b to your computer and use it in GitHub Desktop.
Save daybreaker/42c3626356fb7cd24b5883800b2b583b to your computer and use it in GitHub Desktop.
require 'slack-ruby-client'
require 'byebug'
require 'date'
def count_words(string)
words = string.split(' ')
frequency = Hash.new(0)
words.each { |word| frequency[word.downcase] += 1 }
frequency
end
token = TOKEN
Slack.configure do |config|
config.token = token
end
client = Slack::Web::Client.new
messages = []
while messages.empty? || DateTime.strptime(messages.last.ts,'%s') > Date.parse('2017-01-01') do
messages += messages.any? ?
client.channels_history(channel: '#watercooler', count: 500, latest: messages.last.ts).messages :
client.channels_history(channel: '#watercooler', count: 500).messages
puts messages.count
end
reactions = Hash.new(0)
messages.select { |mess| mess.reactions.present? }.each{ |mess| mess.reactions.each { |reaction| reactions[reaction[:name].split('::').first] += reaction[:count] } }
puts reactions.sort.inspect
puts "The End"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment