Skip to content

Instantly share code, notes, and snippets.

@SwapnilSoni1999
Last active January 30, 2022 19:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SwapnilSoni1999/a0d328f6b3383848e1406833521800b0 to your computer and use it in GitHub Desktop.
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
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