Skip to content

Instantly share code, notes, and snippets.

@hassaku
Created April 1, 2016 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassaku/6fca0c22a392e4a9fa49d6075cdb6867 to your computer and use it in GitHub Desktop.
Save hassaku/6fca0c22a392e4a9fa49d6075cdb6867 to your computer and use it in GitHub Desktop.
Slackの特定ユーザのログ抽出
require 'json'
# 1. CSV export
# https://xxxxx.slack.com/services/export
# 2. Confirm target user ID
# curl https://slack.com/api/users.list?token=YOUR_SLACK_TOKEN
user = "XXXXXX"
export_dir = "export_csv/chanel_name"
year = 2016
month = 3
days = 31
current_date = nil
days.times do |day|
date = sprintf("%d-%02d-%02d", year, month, day + 1)
export_file = "#{export_dir}/#{date}.json"
next unless File.exist?(export_file)
json_data = open(export_file) do |io|
JSON.load(io)
end
json_data.each do |json|
time = Time.at(json['ts'].to_i)
date = time.strftime('%Y/%m/%d')
if current_date != date
puts "\n[#{date}]"
current_date = date
end
puts "#{time.strftime('%H:%M:%S')}: #{json['text'].gsub(/\n+/, ' ')}" if json["user"] == user
end
end
@hassaku
Copy link
Author

hassaku commented Apr 1, 2016

$ ruby extract_utterances.rb
[2016/03/01]
09:26:44: おはようございます〜
...

[2016/03/02]
00:51:14: あああ
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment