Skip to content

Instantly share code, notes, and snippets.

@jamespo
Created June 29, 2012 20:45

Revisions

  1. jamespo created this gist Jun 29, 2012.
    31 changes: 31 additions & 0 deletions parsephpchain.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    '''parsephpchain.py - parse phpchain XML export to CSV'''

    import xml.etree.ElementTree as ET
    import sys

    def parse(file):
    tree = ET.parse(file)
    root = tree.getroot()
    pws = root.findall('pwentry')

    for pw in pws:
    fields = ['username','url','password','title']
    outfields = []
    for field in fields:
    key = pw.find(field)
    if key is not None:
    outfields.append(key.text)
    else:
    outfields.append('')
    print '|'.join(outfields)


    def main(filename):
    parse(filename)


    if __name__ == '__main__':
    main(sys.argv[1])