Skip to content

Instantly share code, notes, and snippets.

@dentarg
Created May 6, 2014 14:45
Show Gist options
  • Save dentarg/5656b8d078e8cfb8dcf3 to your computer and use it in GitHub Desktop.
Save dentarg/5656b8d078e8cfb8dcf3 to your computer and use it in GitHub Desktop.
KeePass 2 XML export to 1Password Mac CSV import http://learn2.agilebits.com/1Password4/Mac/en/KB/import.html
require 'csv'
require 'open-uri'
require 'nokogiri'
file = "keepass.xml"
doc = Nokogiri::XML::Document.parse(open(file)) do |config|
config.noblanks
end ; nil
entries = []
doc.css('Group > Entry').each do |entry|
attributes = {}
attributes["GroupName"] = entry.parent.css('> Name').text
entry.css('String').each do |string|
unless string.css_path.include?('History')
key = string.css('Key').text
value = string.css('Value').text
attributes[key] = value
end
end
entries << attributes
end
content = entries.map do |entry|
[
"#{entry['GroupName']} #{entry['Title']}",
entry['URL'],
entry['UserName'],
entry['Password'],
entry['Notes'],
]
end
CSV.open("1password.csv", "wb") do |csv|
content.each do |row|
csv << row
end
end
@stphnrdmr
Copy link

Thanks for this script, works like a charm from KeePass2 to 1Password 5!

@joetufano
Copy link

worked like a charm. Thanks a bunch!

@rakauchuk
Copy link

Works good! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment