From 3522b0365224184ec756d6e8acddb2aeb1909033 Mon Sep 17 00:00:00 2001 From: diegantobass Date: Thu, 8 May 2025 11:08:57 +0200 Subject: [PATCH] clean addresses --- vcf_cleaner.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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)