Created
April 1, 2016 15:31
-
-
Save hassaku/6fca0c22a392e4a9fa49d6075cdb6867 to your computer and use it in GitHub Desktop.
Slackの特定ユーザのログ抽出
This file contains 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 '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 |
Author
hassaku
commented
Apr 1, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment