Skip to content

Instantly share code, notes, and snippets.

@thehenster
Created August 21, 2014 09:20
Show Gist options
  • Save thehenster/2710bdf337c4d5cf1682 to your computer and use it in GitHub Desktop.
Save thehenster/2710bdf337c4d5cf1682 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Give me two arguments.
# 1) the path of the pwsafe xml file to import
# 2) the path of the csv to export
# format of lastpass data
# url,username,password,extra,name,grouping,fav
require 'nokogiri'
require 'csv'
pwsafe_path, lastpass_path = ARGV[0], ARGV[1]
pwsafe_data = File.read(pwsafe_path)
doc = Nokogiri::XML(pwsafe_data)
CSV.open(lastpass_path, "wb", force_quotes: true) do |csv|
csv << ['url','username','password','extra','name','grouping','fav']
doc.css('pwentry').each do |entry|
row = []
row << nil # url
row << entry.css('username').first.content
row << entry.css('password').first.content
row << entry.css('notes').first.content
row << entry.css('title').first.content
row << entry.css('group').first.content
row << nil # fav
csv << row
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment