Skip to content

Instantly share code, notes, and snippets.

@cyriac
Created November 13, 2014 12:38
Show Gist options
  • Save cyriac/547300ccbfec01f0d331 to your computer and use it in GitHub Desktop.
Save cyriac/547300ccbfec01f0d331 to your computer and use it in GitHub Desktop.
Removes bad contacts created from old orkut days. Keeps only contacts with phone numbers, useful for iCloud contacts import
# Usage: python google_contacts_cleaner.py input.vcf output.vcf
import sys
input_file = sys.argv[1]
output_file = sys.argv[2]
total_card_count = 0
final_card_count = 0
with open(input_file,'r') as f:
results = []
card = []
for line in f:
if ("BEGIN:VCARD" in line):
total_card_count += 1
card = []
card.append(line)
if ("END:VCARD" in line):
for element in card:
if element.startswith("TEL:") or element.startswith("TEL;"):
final_card_count += 1
results.extend(card)
break
print "Total contacts: %s" % (total_card_count)
print "Clean contacts: %s" % (final_card_count)
with open(output_file, 'w') as oFile:
for item in results:
oFile.write(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment