Last active
April 10, 2018 19:43
-
-
Save daybreaker/42c3626356fb7cd24b5883800b2b583b to your computer and use it in GitHub Desktop.
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-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