Skip to content

Instantly share code, notes, and snippets.

@bretthoerner
Created May 12, 2010 02:41
Show Gist options
  • Save bretthoerner/398142 to your computer and use it in GitHub Desktop.
Save bretthoerner/398142 to your computer and use it in GitHub Desktop.
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()
@bretthoerner
Copy link
Author

God, this code is awful.

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