Skip to content

Instantly share code, notes, and snippets.

@jstanley0
Last active May 15, 2019 16:23
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 jstanley0/6612e686fe5654aa4025b152c2413c31 to your computer and use it in GitHub Desktop.
Save jstanley0/6612e686fe5654aa4025b152c2413c31 to your computer and use it in GitHub Desktop.
convert colloquy transcripts into plain text
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