import vobject def remove_duplicates(input_file, output_file): seen = set() unique_contacts = []
with open(input_file, 'r') as f: vcards = f.read().split('END:VCARD') for vcard in vcards: if 'BEGIN:VCARD' not in vcard: continue vcard = vcard + 'END:VCARD' # Use FN (Full Name) as unique key – adjust as needed try: obj = vobject.readOne(vcard) fn = obj.fn.value if hasattr(obj, 'fn') else '' if fn not in seen: seen.add(fn) unique_contacts.append(vcard) except: continue # skip malformed vcards