Created
May 12, 2010 02:41
-
-
Save bretthoerner/398142 to your computer and use it in GitHub Desktop.
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
from lxml import etree | |
import csv | |
import sys | |
if len(sys.argv) != 2: | |
print >> sys.stderr, "Usage: %s <1Password_text_export>" % sys.argv[0] | |
sys.exit(1) | |
reader = csv.reader(open(sys.argv[1]), dialect='excel-tab') | |
headers = reader.next() | |
root = etree.Element("database") | |
group = etree.Element("group") | |
root.append(group) | |
title = etree.Element("title") | |
title.text = "Internet" | |
icon = etree.Element("icon") | |
icon.text = "1" | |
group.append(title) | |
group.append(icon) | |
for row in reader: | |
data = dict(zip(headers, [r.replace("\\n", "\n") for r in row])) | |
entry = etree.Element("entry") | |
group.append(entry) | |
username = etree.Element("username") | |
username.text = data['username'] | |
entry.append(username) | |
password = etree.Element("password") | |
password.text = data['password'] | |
entry.append(password) | |
title = etree.Element("title") | |
title.text = data['title'] | |
entry.append(title) | |
url = etree.Element("url") | |
url.text = data['URL/Location'] | |
entry.append(url) | |
comment = etree.Element("comment") | |
comment.text = data['notes'] | |
entry.append(comment) | |
out = open("1Password.xml", "w") | |
out.write(etree.tostring(root)) | |
out.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
God, this code is awful.