Skip to content

Instantly share code, notes, and snippets.

@manveru
Created June 20, 2010 18:25
Show Gist options
  • Save manveru/445995 to your computer and use it in GitHub Desktop.
Save manveru/445995 to your computer and use it in GitHub Desktop.
require 'csv'
require 'pp'
require 'time'
require 'readline'
require 'nokogiri'
lines = ARGF.read
time = Time.now.iso8601
builder = Nokogiri::XML::Builder.new{|xml|
xml.database do
xml.group do
xml.title 'Internet'
xml.icon 1
CSV.parse(lines, headers: :first_row).each do |row|
xml.entry do
xml.title (row['name'] || row['url']).sub('Generated Password for ', '')
xml.username row['username']
xml.password row['password']
xml.url row['url']
xml.comment row['extra']
xml.icon 1
xml.creation time
xml.lastaccess time
xml.lastmod time
xml.expire 'Never'
end
end
end
end
}
doc = Nokogiri::XML('<!DOCTYPE KEEPASSX_DATABASE>')
doc.add_child(builder.doc.at('database'))
File.open('keepass.xml', 'w+'){|io| io.write(doc.to_xml) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment