Created
November 13, 2014 12:38
-
-
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
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
# 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