Last active
January 30, 2022 19:05
-
-
Save SwapnilSoni1999/a0d328f6b3383848e1406833521800b0 to your computer and use it in GitHub Desktop.
Fix Contacts country code - Add country code to those numbers which have missing country code at start to your vcf file
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 re | |
# Edit these | |
SOURCE_VCF = "27jan22.vcf" # Your source file | |
COUNTRY_CODE = "+91" # Country code you want to add (Tested for India only) | |
OUTPUT_VCF = "27jan22-modded.vcf" # The output file you want | |
# Dont edit below | |
to_save = [] | |
with open(SOURCE_VCF, "r") as vcf: | |
for line in vcf: | |
result = re.findall(r"[0-9]{3}-[0-9]{3}-[0-9]{4}", line) | |
if len(result) and '+1' not in line and '1-' not in line and '+' not in line: | |
print(result[0]) | |
newline = line.replace(result[0],"+91" + result[0].replace("-", "")) | |
to_save.append(newline) | |
else: | |
to_save.append(line) | |
with open(OUTPUT_VCF, "w") as new_vcf: | |
for line in to_save: | |
new_vcf.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment