diff --git a/vcf_cleaner.py b/vcf_cleaner.py index a6d83ae..72f6b42 100644 --- a/vcf_cleaner.py +++ b/vcf_cleaner.py @@ -4,6 +4,7 @@ import sys import quopri import base64 import pickle +import itertools import phonenumbers import pythonvCard4 from pythonvCard4.vcard import Contact @@ -80,9 +81,19 @@ for line in input_file: for value in contact.custom[field]: contact.custom[field] = quopri.decodestring(value).decode() + # notes reencoding if contact.note: contact.note = quopri.decodestring(contact.note).decode() + # deduplicate and reencode address + if contact.adr != []: + adresses = [] + for adresse in contact.adr: + adresses.append([quopri.decodestring(x).decode() for x in adresse["value"]]) + clean = list(k for k,_ in itertools.groupby(adresses)) + clean = [{"value":x, "type":["HOME"]} for x in clean] + contact.adr = clean + # rewrite contact as vcard vcf_text = contact.to_vcard() output.write(vcf_text)