Created
November 18, 2014 22:35
-
-
Save Techbrunch/96607a107f2857a83f56 to your computer and use it in GitHub Desktop.
Small script to convert Keepass XML file to CVS that can be imported by 1Password
This file contains 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 'nokogiri' | |
require 'base64' | |
require 'csv' | |
file = File.new("1password.csv", "w") | |
f = File.open(ARGV[0]) | |
doc = Nokogiri::XML(f) | |
f.close | |
items = doc.xpath('//Group/Entry') | |
puts items.count | |
CSV.open("1password.csv", "w") do |csv| | |
csv.puts(['title','url','username','password','comment']) | |
items.each do |item| | |
title = item.xpath('String[Key="Title"]/Value').text.force_encoding('UTF-8').empty? ? 'No title' : item.xpath('String[Key="Title"]/Value').text.force_encoding('UTF-8') | |
username = item.xpath('String[Key="UserName"]/Value').text.force_encoding('UTF-8') | |
password = item.xpath('String[Key="Password"]/Value').text.force_encoding('UTF-8') | |
url = item.xpath('String[Key="URL"]/Value').text.force_encoding('UTF-8') | |
comment = item.xpath('String[Key="Notes"]/Value').text.force_encoding('UTF-8') | |
# https://learn2.agilebits.com/1Password4/Mac/en/KB/import.html | |
csv.puts([title,url,username,password,comment]) | |
end | |
end | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: ./keepass_to_1password.rb keepass.xml