Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Convert 1Password .csv file to the KeePassX xml format
- # Note: Ignores categories
- import sys
- import csv
- import unicodedata
- import lxml.etree as ET
- # Maps fields names from 1Password to KeepPassX
- FIELD_MAP = {
- 'title': 'title',
- 'username': 'username',
- 'password': 'password',
- 'URL/Location': 'url',
- 'notes': 'comment'
- }
- if len(sys.argv) != 3:
- print 'Usage: ./convert <input 1Password file> <output keepassx file>'
- sys.exit(1)
- input_file = sys.argv[1]
- output_file = sys.argv[2]
- with open(input_file, 'r') as fp:
- reader = csv.DictReader(fp, delimiter='\t',
- doublequote=True,
- quoting=csv.QUOTE_ALL)
- root = ET.Element('database')
- group = ET.SubElement(root, 'group')
- title = ET.SubElement(group, 'title')
- title.text = 'Internet'
- icon = ET.SubElement(group, 'icon')
- icon.text = '1'
- skipped = 0
- for index, row in enumerate(reader):
- entry = ET.SubElement(group, 'entry')
- for name1, name2 in FIELD_MAP.items():
- value = unicode(row[name1], 'utf-8')
- if name1 == 'notes' and value == '\\n\\n':
- value = u''
- unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
- item = ET.SubElement(entry, name2)
- item.text = value
- print 'Processed %d entries' % (index - skipped)
- tree = ET.ElementTree(root)
- tree.write(output_file)
- print 'Written to %s' % (output_file)
Add Comment
Please, Sign In to add comment