Skip to content

Instantly share code, notes, and snippets.

@boxmein
Last active January 4, 2016 22:14
Show Gist options
  • Save boxmein/c34c840bdf96f9fb10be to your computer and use it in GitHub Desktop.
Save boxmein/c34c840bdf96f9fb10be to your computer and use it in GitHub Desktop.
Ruby script to naively consolidate a bunch of HexChat logs. You can figure out date order etc yourself. Mwahahahah
#!/usr/bin/env ruby
# Ruby script to consolidate all my log folders
require 'thread'
PREFIX="/home/#{`whoami`}/.config/hexchat/logs/"
FOLDERS=["freenode", "freenode over znc", "poke_freenode"]
file_q = Queue.new
threads = []
puts "\n---\nScanning the folders for logs..."
FOLDERS.each do |folder|
log_dir = File.join(PREFIX, folder, "*.log")
puts "Looking for logs in #{log_dir}"
Dir.glob(log_dir) do |file|
puts "Queuing file for copying: #{file}"
file_q << file
end
end
4.times do
threads << Thread.new do
until file_q.empty?
infile_name = file_q.pop
outfile_name = File.join("./freenode/", File.basename(infile_name))
puts "Copying file #{infile_name} to #{outfile_name}"
File.open(infile_name, "r") do |infile|
File.open(outfile_name, "a") do |outfile|
while line = infile.gets
outfile.puts line
end
end
end
end
end
end
threads.map &:join
puts "Finished consolidating logs, hopefully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment