Ahmad Nour
Ahmad Nour

Reputation: 9

vcf files reading and editing with python

I have vcf file of my business contacts , I need to edit the names saved in the file contact using a code but it seems it's not working with vcf modules so , please help it's more than 3k phone number

i tried to install pyvcf ,vcf module ,and pip has upgraded also" environment "is good

Upvotes: -1

Views: 604

Answers (1)

AX Maximus
AX Maximus

Reputation: 21

def update_vcf_contacts(input_file, output_file):
    updated_lines = []

    with open(input_file, 'r') as f:
        for line in f:
            if line.startswith('FN:'):
                # Modify the contact name here, for example, add a suffix '-Edited'
                updated_line = line.strip() + '-Edited\n'
            else:
                updated_line = line

            updated_lines.append(updated_line)

    with open(output_file, 'w') as f:
        f.writelines(updated_lines)


if __name__ == "__main__":
    input_vcf_file = "input.vcf"
    output_vcf_file = "output.vcf"

    update_vcf_contacts(input_vcf_file, output_vcf_file)

Upvotes: 1

Related Questions