Created
November 3, 2011 04:00
-
-
Save hkurosawa/1335747 to your computer and use it in GitHub Desktop.
converts pastor export tsv to KeePassX xml import
This file contains hidden or 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
| """ | |
| converts pastor export tsv to KeePassX xml import | |
| """ | |
| import sys, time | |
| from xml.sax.saxutils import * | |
| header = """<!DOCTYPE KEEPASSX_DATABASE> | |
| <database> | |
| <group> | |
| <title>Pastor Imports</title> | |
| <icon>48</icon> | |
| """ | |
| footer = """</group> | |
| </database> | |
| """ | |
| now = time.strftime('%Y-%m-%dT%H:%M:%S') | |
| def convert(src, dst): | |
| f = open(src, 'r') | |
| str = f.readlines()[0] | |
| f.close() | |
| entries = str.split('\r') | |
| outf = open(dst, 'w') | |
| outf.write(header) | |
| for e in entries: | |
| if len(e)<=:0: | |
| continue | |
| try: | |
| (pastor_name, pastor_url, pastor_id, pastor_pass, pastor_note) = e.split('\t') | |
| outf.write('<entry>\n') | |
| outf.write('<title>'+escape(pastor_name)+'</title>\n') | |
| outf.write('<username>'+escape(pastor_id)+'</username>\n') | |
| outf.write('<password>'+escape(pastor_pass)+'</password>\n') | |
| outf.write('<url>'+escape(pastor_url)+'</url>\n') | |
| outf.write('<comment>'+escape(pastor_note)+'</comment>\n') | |
| outf.write('<icon>0</icon>\n') | |
| outf.write('<creation>'+now+'</creation>\n') | |
| outf.write('<lastaccess>'+now+'</lastaccess>\n') | |
| outf.write('<lastmod>'+now+'</lastmod>\n') | |
| outf.write('<expire>Never</expire>\n') | |
| outf.write('</entry>\n') | |
| except ValueError: | |
| print '[WARN]parse error -- ignore:', e | |
| pass | |
| outf.write(footer) | |
| outf.close() | |
| if __name__ == '__main__': | |
| if len(sys.argv) != 3: | |
| print 'usage: pastor2keepass srcfile destfile' | |
| exit() | |
| else: | |
| src = sys.argv[1] | |
| dst = sys.argv[2] | |
| convert(src, dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment