Skip to content

Instantly share code, notes, and snippets.

@albanpeignier
Created October 26, 2010 09:43
Show Gist options
  • Select an option

  • Save albanpeignier/646609 to your computer and use it in GitHub Desktop.

Select an option

Save albanpeignier/646609 to your computer and use it in GitHub Desktop.
Transform revelation xml export in a csv file (for PassPack, for example)
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
passwords = Nokogiri::XML(IO.read(ARGV.first))
def tags_for(entry)
if entry.parent.attribute("type").to_s == "folder"
[entry.parent.xpath('name').text.downcase] + tags_for(entry.parent)
else
[]
end
end
passwords.xpath("//entry").each do |entry|
unless entry.attribute("type").to_s == "folder"
line = [ entry.xpath("name"),
entry.xpath('field[@id="generic-username"]'),
entry.xpath('field[@id="generic-password"]'),
(entry.xpath('field[@id="generic-url"]') or entry.xpath('field[@id="generic-hostname"]')),
entry.xpath('field[@id="generic-email"]'),
tags_for(entry).join(' ')
].collect do |value|
value = value.text if value.respond_to?(:text)
value or ""
end.join(",")
puts line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment