Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This script makes many .vcf files from one if you exported
# it from google contacts as Apple vcf format.
# For nokia symbian s60 phones create dir on flash card
# E:/Others/Contacts and move all vcf files in those dir.
# N means Name and FN — surname in vcard.
# Non ascii symbols has to be encoded in QUOTED-PRINTABLE.
import re
from quopri import encodestring
with open('../contacts.vcf') as f:
data = f.read()
p = re.compile(r'BEGIN:VCARD.*?END:VCARD', re.S)
vcards = re.findall(p, data)
for vcard in vcards:
if 'CELL' in vcard:
vcard = vcard.split('\n')
filename = vcard[2].replace('FN:', '')
n = filename.split()
name = encodestring(bytes(n[0], 'utf8'))
last = encodestring(bytes(' '.join(n[1:]), 'utf8'))
N = 'N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:;{};;;'.format(
name.decode('utf8'))
FN = 'FN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:{}'.format(
last.decode('utf8'))
vcard[2] = FN
vcard[3] = N
with open('Contacts/{}.vcf'.format(filename), 'w') as f:
f.write('\n'.join(vcard))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.