clean addresses
This commit is contained in:
parent
585acde380
commit
3522b03652
1 changed files with 11 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue