Mar-05-2021, 08:33 AM
It was easier to look at doing this with the LDIF format. Here is the code:
Can any improvements be done to the code ? For example, it seems a waste having to do all those "if" statements; possibly python has some sort of lookup function, to lookup within the class ?
#!/usr/bin/env python from ldif3 import LDIFParser from pprint import pprint parser = LDIFParser(open("claws_export.ldif", "rb")) for dn, record in parser.parse(): name = "" if 'cn' in record: name = record['cn'][0] surname = "" if 'sn' in record: surname = record['sn'][0] given_name = "" if 'givenName' in record: given_name = record['givenName'][0] display_name = "" if 'displayName' in record: display_name = record['displayName'][0] email = "" if 'mail' in record: email = record['mail'][0] print ('BEGIN:VCARD') print ('VERSION:2.1') print ("N:" + surname + ";" + given_name + ";;;") print ("FN:" + name) print ("EMAIL;HOME:" + email) print ("END:VCARD")The o/p data looks like it is nearly matching what is required for import into the Galaxy contacts. If I did a
print(record)this was the output
Quote:OrderedDict([('objectClass', ['inetOrgPerson']), ('cn', ['Forrest Gump']), ('sn', ['Gump']), ('displayName', ['Forrest Gump']), ('mail', ['[email protected]'])])
Can any improvements be done to the code ? For example, it seems a waste having to do all those "if" statements; possibly python has some sort of lookup function, to lookup within the class ?