Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Сonvert vCards into suitable for Nokia Series 30+ format
r"""
vCard_S30.py -- Convert vCards into suitable for Nokia Series 30+ format, or
How to solve the only one phone number per contact problem.
1) Import contacts "contacts.vcf" from Google account (vCard format).
2) Place it beside this script.
3) Run the script with Python 2.7.
4) Copy the result "backup.dat" into "Backup" folder on the phone SD card.
5) Restore contacts from backup on the phone.
Tested on Nokia 220.
The MIT License (MIT)
Copyright (c) 2016 in4lio@gmail.com
"""
import sys
import os
CARD = """
BEGIN:VCARD
VERSION:2.1
FN:%s
TEL;VOICE;CELL:%s
END:VCARD
"""
cp = sys.stdout.encoding if sys.stdout.encoding else 'utf8'
sou = map( str.strip, open( './contacts.vcf' ).read().splitlines())
res = open( './backup.dat', 'w' )
err = 0
mark = None
for s in sou:
if s == 'BEGIN:VCARD':
print '{',
fn = ''
tel = []
mark = 'FN:'
elif s == 'END:VCARD':
print '}'
if not fn:
print '#### ERROR: NO NAME ####'
err += 1
elif not tel:
print '#### ERROR: NO PHONE ####'
err += 1
else:
for i, t in enumerate( tel ):
res.write( CARD % ( fn + ( ' %d' % i if i else '' ), t ))
mark = None
elif mark and s.startswith( mark ):
if len( s ) > len( mark ):
fn = s.split( ':', 1 )[ 1 ]
print s.decode( 'utf8' ).encode( cp, 'replace' ),
else:
mark = 'ORG:'
elif mark and s.startswith( 'TEL' ):
tel.append( s.split( ':', 1 )[ 1 ])
print s,
res.close()
print '#### DONE ####'
if err:
print '%d ignored contact(s)' % err
@totoroot-fr
Copy link

totoroot-fr commented May 4, 2017

Works also with Nokia 150, but put backup.dat file on SD card root, not in Backup folder :)

@yoelk
Copy link

yoelk commented Nov 16, 2017

Thanks a lot!
Worked like a charm

@fperucic
Copy link

fperucic commented Jul 30, 2018

<3

@beingshon
Copy link

beingshon commented May 10, 2019

Thanks mate !!!
It worked for me ( Nokia 150 )

@kaushalparik27
Copy link

kaushalparik27 commented Aug 12, 2019

Thank you! worked on Nokia 130 DS too.

@alfredbez
Copy link

alfredbez commented Jan 10, 2020

Worked for me on a Nokia 230 👍

@eugeneonline
Copy link

eugeneonline commented Oct 23, 2020

I installed pycharm and python 2.7 and I have following error:
line 49, in <module> elif s.startswith( mark ): NameError: name 'mark' is not defined

In linux also same error:

$ python2.7 vCard_S30.py Traceback (most recent call last): File "vCard_S30.py", line 52, in <module> elif s.startswith( mark ): NameError: name 'mark' is not defined

@in4lio
Copy link
Author

in4lio commented Oct 25, 2020

I fixed the script, but most likely there is an issue with "contacts.vcf" contents.

@kmishal
Copy link

kmishal commented Jan 1, 2021

Worked like a charm..! thanks!

@Sayed-Shifat-Ahmed
Copy link

Sayed-Shifat-Ahmed commented Apr 17, 2021

its work in Nokia 225

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