Created
May 18, 2017 11:07
-
-
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.
This file contains 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' | |
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