Created
July 15, 2023 22:29
-
-
Save franklinmoy3/d12833b7324798309303e31b4f3c1b2f to your computer and use it in GitHub Desktop.
Split Google Contacts VCF file containing multiple contact cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
END_VCARD = "END:VCARD\n" | |
in_file = "./contacts.vcf" | |
out_file_format = "./contacts_out/contact_{}.vcf" | |
with open(in_file, "r") as input_file: | |
contents_as_string = input_file.read() | |
arr = [e+END_VCARD for e in contents_as_string.split(END_VCARD) if e] | |
os.makedirs(os.path.dirname(out_file_format), exist_ok=True) | |
for i, vcf in enumerate(arr): | |
out_file_name = out_file_format.format(i) | |
print(f"Wrote below to {out_file_name}:\n", vcf, sep="") | |
with open(out_file_name, "x") as output_file: | |
output_file.write(vcf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment