Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created June 17, 2013 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjameshuff/5797609 to your computer and use it in GitHub Desktop.
Save cjameshuff/5797609 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# ./totext.rb FILENAME
require "rexml/document"
puts "Converting #{ARGV[0]}"
fin = File.new(ARGV[0])
doc = REXML::Document.new(fin)
fout = File.new(File.basename(ARGV[0], ".colloquyTranscript") + ".txt", "w")
def all_text(elem)
elem.to_a.map {|ch|
(ch.is_a? REXML::Text)? REXML::Text.unnormalize(ch.to_s) : all_text(ch)
}.join
end
doc.elements.each("log/envelope") {|element|
sender = element.elements["sender"].text
element.elements.each("message") {|msg|
if(msg.attributes["action"] == "yes")
fout.puts "* #{sender} #{all_text(msg)}"
else
fout.puts "<#{sender}> #{all_text(msg)}"
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment