Skip to content

Instantly share code, notes, and snippets.

@szczys
Created December 14, 2011 20:22
Show Gist options
  • Save szczys/1478337 to your computer and use it in GitHub Desktop.
Save szczys/1478337 to your computer and use it in GitHub Desktop.
Python script for splitting a VCARD file to a user-set number of VCARDs per output file
#split vcf files
working_dir = '/home/mike/compile/'
input_file = 'final.vcf'
output_seed = 'contacts-part-'
vcards_per_file = 75
with open(working_dir + input_file,'r') as f:
count = 0
output_count = 1
results = []
for line in f:
if ("BEGIN:VCARD" in line):
count += 1
if (count <= vcards_per_file):
results.append(line)
else:
#output file with stored values
with open(working_dir + output_seed + str(output_count) + '.vcf','w') as oFile:
for item in results:
oFile.write(item)
#increment outputfile count
output_count += 1
#clear results list and append last read line
del results[:]
results.append(line)
#set counter back to 1
count = 1
#write the last set of results to a file
with open(working_dir + output_seed + str(output_count) + '.vcf','w') as oFile:
for item in results:
oFile.write(item)
@umrashrf
Copy link

Google Contacts VCard Last;First to First;Last name conversion https://gist.github.com/umrashrf/4d402f0ac9477036f016#file-vcard-split-py-L20-L22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment