Bug fix on empty contact list when using --enrich-from-vcards

This commit is contained in:
KnugiHK
2024-09-11 00:23:13 +08:00
parent 884ccc4cc0
commit df67a549c0

View File

@@ -33,11 +33,16 @@ def read_vcards_file(vcf_file_path, default_country_code: str):
with open(vcf_file_path, mode="r", encoding="utf-8") as f: with open(vcf_file_path, mode="r", encoding="utf-8") as f:
reader = vobject.readComponents(f) reader = vobject.readComponents(f)
for row in reader: for row in reader:
if not hasattr(row, 'fn') or not hasattr(row, 'tel'): if hasattr(row, 'fn'):
name = str(row.fn.value)
elif hasattr(row, 'n'):
name = str(row.n.value)
else:
name = None
if not hasattr(row, 'tel') or name is None:
continue continue
contact: ExportedContactNumbers = { contact: ExportedContactNumbers = {
"full_name": row.fn.value, "full_name": name,
"numbers": list(map(lambda tel: tel.value, row.tel_list)), "numbers": list(map(lambda tel: tel.value, row.tel_list)),
} }
contacts.append(contact) contacts.append(contact)