Hello,
with this script I can import vcards in an utf-8 file (with umlauts etc.) with PyS60 1.1.3pre (Series 60 1.2):
This is not possible anymore with 1.1.5 (with the exact same vcf-file), the vcard_import method fails withCode:import re import contacts import codecs import graphics import e32 import appuifw expremptyline = re.compile(r"\r\n\r\n", re.IGNORECASE & re.MULTILINE) exprswitchtel = re.compile(r"TEL\;TYPE=", re.IGNORECASE & re.MULTILINE) def exportforseries60(vcard): return exprswitchtel.sub(r"TEL;", vcard) def readfile(filename): file = codecs.open(filename,"r","utf8") inhalt = file.read() file.close() return inhalt def writetext(s,clear = True,x = 2, y = 12): if clear: draw.clear() draw.text((x,y),s,0x008000) def carryon(event): global lockjc lockjc.signal() def quit(): global lockjc lockjc.signal() #so it won't be locked in any case appuifw.app.exit_key_handler=None #don't know if this is necessary appuifw.app.set_exit() appuifw.app.title=u"Import VCards" canvas=appuifw.Canvas(event_callback=carryon) appuifw.app.body=canvas draw=graphics.Draw(canvas) lockjc=e32.Ao_lock() appuifw.app.exit_key_handler=quit vcardstrings = expremptyline.split(readfile(r"e:\python\addressbook.vcf")) #last line is an empty newline (ist Kontact schuld) writetext(u"%s VCards aus Datei geöffnet"%(len(vcardstrings)-1)) contactdb = contacts.open() allenamen = contactdb.keys() laengeallenamen = len(allenamen) writetext(u"Es sind %s Kontakte im Telefonbuch vorhanden."%(laengeallenamen),False,2,25) lockjc.wait() for i in range(laengeallenamen): writetext(u"Lösche Kontakt Nr.: %s/%s"%(i+1, laengeallenamen)) e32.ao_yield() del contactdb[allenamen[i]] #Missing here is the compact method to get the db-file small again (see other post of mine) #appuifw.note(u"Alle %s Kontakte gelöscht..."%(laengeallenamen),"info") #contactdb.compact() print "Alle gelöscht" laengevcardstring = len(vcardstrings) for g in range(laengevcardstring): writetext(u"Importiere VCard Nr.: %s/%s"%(g, laengevcardstring-1)) contactdb.import_vcards(exportforseries60(vcardstrings[g])) e32.ao_yield() allenamen = contactdb.keys() laengeallenamen = len(allenamen) writetext(u"Komprimiere Telefonbuch...",False,2,25) #contactdb.compact() contactdb.close() appuifw.note(u"%s Kontakte importiert!"%(laengeallenamen),"info")
I think the relevant parts are the method where I read the file via codecs.open(f,"r","utf8") and the method to import the vcard in the database.Code:Traceback (most recent call last): File "E:\System\Apps\Python\my\syncandrunclient.py", line 154, in run execfile(target, g) File "e:\python\vcardimportseries60.py", line 66, in ? contactdb.import_vcards(exportforseries60(vcardstrings[g])) File "E:\system\libs\contacts.py", line 157, in import_vcards return [self[x] for x in self._db.import_vcards(unicode(vcards),vcard_flags)] UnicodeError: ASCII encoding error: ordinal not in range(128)
Is there any change between 1.1.3pre and 1.1.5 concerning the handling of unicode data?
Thanks,
Joost

Reply With Quote


