From 5d9f7f0efc00f7788cb9527d6bc0ddefa73f68fc Mon Sep 17 00:00:00 2001 From: Christian Sirolli <34974905+HeyITGuyFixIt@users.noreply.github.com> Date: Thu, 2 Jun 2022 09:55:56 -0400 Subject: [PATCH 1/3] Make Columns Optional Use get with a default value of "" to prevent key errors if columns are missing. --- csv2vcard/create_vcard.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/csv2vcard/create_vcard.py b/csv2vcard/create_vcard.py index 63616dd..22e881a 100644 --- a/csv2vcard/create_vcard.py +++ b/csv2vcard/create_vcard.py @@ -4,22 +4,22 @@ def create_vcard(contact: dict): """ vc_begin = "BEGIN:VCARD\n" vc_version = "VERSION:3.0\n" - vc_name = f"N;CHARSET=UTF-8:{contact['last_name']};{contact['first_name']};;;\n" - vc_title = f"TITLE;CHARSET=UTF-8:{contact['title']}\n" - vc_org = f"ORG;CHARSET=UTF-8:{contact['org']}\n" - vc_phone = f"TEL;TYPE=WORK,VOICE:{contact['phone']}\n" - vc_email = f"EMAIL;TYPE=WORK:{contact['email']}\n" - vc_website = f"URL;TYPE=WORK:{contact['website']}\n" - vc_address = f"ADR;TYPE=WORK;CHARSET=UTF-8:{contact['street']};{contact['city']};{contact['p_code']};{contact['country']}\n" + vc_name = f"N;CHARSET=UTF-8:{contact.get('last_name', '')};{contact.get('first_name', '')};;;\n" + vc_title = f"TITLE;CHARSET=UTF-8:{contact.get('title', '')}\n" + vc_org = f"ORG;CHARSET=UTF-8:{contact.get('org', '')}\n" + vc_phone = f"TEL;TYPE=WORK,VOICE:{contact.get('phone', '')}\n" + vc_email = f"EMAIL;TYPE=WORK:{contact.get('email', '')}\n" + vc_website = f"URL;TYPE=WORK:{contact.get('website', '')}\n" + vc_address = f"ADR;TYPE=WORK;CHARSET=UTF-8:{contact.get('street', '')};{contact.get('city', '')};{contact.get('p_code', '')};{contact.get('country', '')}\n" vc_end = "END:VCARD\n" - vc_filename = f"{contact['last_name'].lower()}_{contact['first_name'].lower()}.vcf" + vc_filename = f"{contact.get('last_name', '').lower()}_{contact.get('first_name', '').lower()}.vcf" vc_output = vc_begin + vc_version + vc_name + vc_title + vc_org + vc_phone + vc_email + vc_website + vc_address + vc_end vc_final = { "filename" : vc_filename, "output" : vc_output, - "name" : contact['first_name'] + contact['last_name'], + "name" : contact.get('first_name', '') + contact.get('last_name', ''), } return vc_final From 87a5f7722452d7ceeab18a735579a276162c4a00 Mon Sep 17 00:00:00 2001 From: Christian Sirolli <34974905+HeyITGuyFixIt@users.noreply.github.com> Date: Thu, 2 Jun 2022 13:41:21 -0400 Subject: [PATCH 2/3] Update create_vcard.py --- csv2vcard/create_vcard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/csv2vcard/create_vcard.py b/csv2vcard/create_vcard.py index 22e881a..9a6c321 100644 --- a/csv2vcard/create_vcard.py +++ b/csv2vcard/create_vcard.py @@ -5,11 +5,11 @@ def create_vcard(contact: dict): vc_begin = "BEGIN:VCARD\n" vc_version = "VERSION:3.0\n" vc_name = f"N;CHARSET=UTF-8:{contact.get('last_name', '')};{contact.get('first_name', '')};;;\n" - vc_title = f"TITLE;CHARSET=UTF-8:{contact.get('title', '')}\n" - vc_org = f"ORG;CHARSET=UTF-8:{contact.get('org', '')}\n" - vc_phone = f"TEL;TYPE=WORK,VOICE:{contact.get('phone', '')}\n" - vc_email = f"EMAIL;TYPE=WORK:{contact.get('email', '')}\n" - vc_website = f"URL;TYPE=WORK:{contact.get('website', '')}\n" + vc_title = f"TITLE;CHARSET=UTF-8:{contact.get('title', '')}\n" if contact.get('title', '') != '' else "" + vc_org = f"ORG;CHARSET=UTF-8:{contact.get('org', '')}\n" if contact.get('org', '') != '' else "" + vc_phone = f"TEL;TYPE=WORK,VOICE:{contact.get('phone', '')}\n" if contact.get('phone', '') != '' else "" + vc_email = f"EMAIL;TYPE=WORK:{contact.get('email', '')}\n" if contact.get('email', '') != '' else "" + vc_website = f"URL;TYPE=WORK:{contact.get('website', '')}\n" if contact.get('website', '') != '' else "" vc_address = f"ADR;TYPE=WORK;CHARSET=UTF-8:{contact.get('street', '')};{contact.get('city', '')};{contact.get('p_code', '')};{contact.get('country', '')}\n" vc_end = "END:VCARD\n" From e24f9985186846058e707646fbc03ba43b2e630c Mon Sep 17 00:00:00 2001 From: Christian Sirolli <34974905+HeyITGuyFixIt@users.noreply.github.com> Date: Thu, 2 Jun 2022 13:43:31 -0400 Subject: [PATCH 3/3] Added FN iOS requires both N and FN to be imported --- csv2vcard/create_vcard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/csv2vcard/create_vcard.py b/csv2vcard/create_vcard.py index 9a6c321..ef669e0 100644 --- a/csv2vcard/create_vcard.py +++ b/csv2vcard/create_vcard.py @@ -5,6 +5,7 @@ def create_vcard(contact: dict): vc_begin = "BEGIN:VCARD\n" vc_version = "VERSION:3.0\n" vc_name = f"N;CHARSET=UTF-8:{contact.get('last_name', '')};{contact.get('first_name', '')};;;\n" + vc_fullname = f"FN;CHARSET=UTF-8:{contact.get('first_name', '')} {contact.get('last_name', '')}\n" vc_title = f"TITLE;CHARSET=UTF-8:{contact.get('title', '')}\n" if contact.get('title', '') != '' else "" vc_org = f"ORG;CHARSET=UTF-8:{contact.get('org', '')}\n" if contact.get('org', '') != '' else "" vc_phone = f"TEL;TYPE=WORK,VOICE:{contact.get('phone', '')}\n" if contact.get('phone', '') != '' else ""