Skip to content

Instantly share code, notes, and snippets.

@moonhouse
Created June 8, 2017 14:02
Show Gist options
  • Select an option

  • Save moonhouse/48874acbf23dca6b2dc1515b3ec9c657 to your computer and use it in GitHub Desktop.

Select an option

Save moonhouse/48874acbf23dca6b2dc1515b3ec9c657 to your computer and use it in GitHub Desktop.
Create list of three letter acronyms used in a Slack team with example usage
require 'zip'
require 'json'
infile = ARGV[0]
tlas = {}
Zip::File.open(infile) do |zip_file|
entries = zip_file.glob('*/*.json')
entries.each do |entry|
messages = JSON.parse(entry.get_input_stream.read)
messages.each do |msg|
matches = msg["text"].match(/\s([A-Z]{3,3})\s/)
unless matches.nil?
tlas[matches[1]] = msg["text"].gsub("\n"," ").gsub("\t"," ")
end
end
end
end
tlas = Hash[tlas.sort_by{|k,v| k}]
tlas.each do |tla,val|
puts "#{tla}\t#{val}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment