Created
June 20, 2010 18:25
-
-
Save manveru/445995 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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