I tried many times but no luck. I want to parse a text file with a vcard format (from my phone contacts).
the text file looks like this:
BEGIN:VCARD
VERSION:2.1
REV:20110913T095232Z
UID:aac119d5fe3bc9dc-00e17913379d6cc8-3
N;X-EPOCCNTMODELLABEL1=First name:;Maj;;;
TEL;VOICE:09120000000
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083215Z
UID:aac119d5fe3bc9dc-00e17b0693898c98-4
N;X-EPOCCNTMODELLABEL1=First name:;Ali jahan;;;
TEL;VOICE:09120000001
X-CLASS:private
END:VCARD
BEGIN:VCARD
VERSION:2.1
REV:20110228T083510Z
UID:aac119d5fe3bc9dc-00e17b069df653a0-5
N;X-EPOCCNTMODELLABEL0=Last name;X-EPOCCNTMODELLABEL1=First name:Eqlimi;Mostafa;;;
TEL;CELL;1:+989120000002
TEL;VOICE:09180000003
X-CLASS:private
TEL;CELL;2:09390000004
X-CLASS:private
END:VCARD
I pasted three different pieces of data and i bolded the info i want to extract.
the output i like to have is a dict like this:
name_numbers = {'Maj':'09120000000', 'Ali jahan':'09120000001', 'Eqlimi Mostafa':'09120000002'}
the code i made so far is:
data = open('contacts.vcf', 'r')
name = ''
number = ''
if data:
for l in data:
if l.startwith('N;'):
name = l.split(':')[1].strip(';')
if l.startwith('TEL'):
number = l.split(':')[1]
print "%s: %s"%(name, number)
P.S: Im using python on my phone and the python on my phone is python 2.2.2
by the way, I need this for a free application for symbian nokia phones and its not a homework.
thanks in advance for any help