Skip to content

Instantly share code, notes, and snippets.

@nmeylan
Created April 11, 2016 09:26
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 nmeylan/eea667e354a057e244cede395044f470 to your computer and use it in GitHub Desktop.
Save nmeylan/eea667e354a057e244cede395044f470 to your computer and use it in GitHub Desktop.
require "oga"
input = "" # sms backup xml file
output = "" #sms export txt file
file = File.open(input, "r:UTF-8")
from_hash = {"1" => "From", "2" => "Me"}
messages = []
document = Oga.parse_xml(file)
document.xpath("allsms/sms").each do |node|
messages << "#{from_hash[node.get(:type)]} (#{node.get(:time)}): #{node.get(:body)}".encode("UTF-8")
end
messages = messages.reverse
file.close
output = File.open(output, "w:UTF-8") do |file|
file.write(messages.join("\r\n"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment