Last active
July 21, 2017 12:05
-
-
Save conformist-mw/81ca6ff03e52e6d16ed09cd43b8578ae to your computer and use it in GitHub Desktop.
This file contains 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
# 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