Last active
May 15, 2019 16:23
-
-
Save jstanley0/6612e686fe5654aa4025b152c2413c31 to your computer and use it in GitHub Desktop.
convert colloquy transcripts into plain text
This file contains hidden or 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 'nokogiri' | |
require 'uri' | |
INTERESTING_EVENTS = %w(memberJoined memberParted memberNewNickname) | |
def format_ts(ts) | |
ts.sub(/ [+-]\d\d\d\d/, '') | |
end | |
Nokogiri::XML(ARGF).css('log').each do |log| | |
channel = URI::decode(log.attr('source')[/[^\/]+$/]) | |
log.css('envelope,event').each do |e| | |
case e.name | |
when 'envelope' | |
sender = e.at_css('sender')&.text | |
e.css('message').each do |message| | |
ts = format_ts(message.attr('received')) | |
puts "#{ts} #{channel} #{sender}: #{message.text.strip}" | |
end | |
when 'event' | |
if INTERESTING_EVENTS.include?(e.attr('name')) | |
ts = format_ts(e.attr('occurred')) | |
text = e.at_css('message')&.text | |
puts "#{ts} #{channel} ** #{text}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment