Skip to content

Instantly share code, notes, and snippets.

@BenjaminKim
Created May 18, 2017 11: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 BenjaminKim/175bbdd9a4c0d7f34cac87953367eeb8 to your computer and use it in GitHub Desktop.
Save BenjaminKim/175bbdd9a4c0d7f34cac87953367eeb8 to your computer and use it in GitHub Desktop.
It parses msn old xml format log and converts it to general txt format.
require 'nokogiri'
def convert
name = '/home/benjamin/Downloads/msn_file_name.xml'
File.open('/home/benjamin/Downloads/result.txt', 'w+') do |f|
doc = Nokogiri::XML(File.read(name))
doc.xpath('//Message').each do |message|
from = message.at_xpath('From/User/@FriendlyName')
to = message.at_xpath('To/User/@FriendlyName')
content = message.at_xpath('Text').content
datetime = DateTime.parse(message.at_xpath('@DateTime')).localtime
f.write "[#{datetime.localtime}] #{from}:\t#{content}\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment