def testMatches(self):
		strErik = """BEGIN:VCARD
VERSION:3.0
FN:null
N:;;;;
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD
"""
		erikcard=vCardWithMatches(parsevCard(vobject.readOne(StringIO.StringIO(strErik))))
		strErik2 = """BEGIN:VCARD
VERSION:3.0
FN:Lars Erik Gewalli
N:Gewalli hotml;Lars;Erik;;
EMAIL;TYPE=INTERNET:[email protected]
NOTE:Phone\\:\\nUser 2\\: [email protected]\\n
END:VCARD
"""
		erikcard2=vCardWithMatches(parsevCard(vobject.readOne(StringIO.StringIO(strErik2))))
		self.assertFalse(erikcard2.matches(erikcard))
		strErik3="""BEGIN:VCARD
VERSION:3.0
FN:Erik M
N:Erik;M;;;
END:VCARD"""
		erikcard3=vCardWithMatches(parsevCard(vobject.readOne(StringIO.StringIO(strErik3))))
		#higher similarity is better
		self.assertFalse(erikcard3.matches(erikcard))

		pass
예제 #2
0
    def testMatches(self):
        strErik = """BEGIN:VCARD
VERSION:3.0
FN:null
N:;;;;
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD
"""
        erikcard = vCardWithMatches(
            parsevCard(vobject.readOne(StringIO.StringIO(strErik))))
        strErik2 = """BEGIN:VCARD
VERSION:3.0
FN:Lars Erik Gewalli
N:Gewalli hotml;Lars;Erik;;
EMAIL;TYPE=INTERNET:[email protected]
NOTE:Phone\\:\\nUser 2\\: [email protected]\\n
END:VCARD
"""
        erikcard2 = vCardWithMatches(
            parsevCard(vobject.readOne(StringIO.StringIO(strErik2))))
        self.assertFalse(erikcard2.matches(erikcard))
        strErik3 = """BEGIN:VCARD
VERSION:3.0
FN:Erik M
N:Erik;M;;;
END:VCARD"""
        erikcard3 = vCardWithMatches(
            parsevCard(vobject.readOne(StringIO.StringIO(strErik3))))
        #higher similarity is better
        self.assertFalse(erikcard3.matches(erikcard))

        pass
예제 #3
0
def main():
    applelist = []
    for x in vobject.readComponents(file("vCard-kort.vcf")):
        card = parsevCard(x)
        card.apple = True
        applelist.append(vCardWithMatches(card))

    googlelist = []
    for x in vobject.readComponents(file("contacts.vcf")):
        card = parsevCard(x)
        card.apple = False
        googlelist.append(vCardWithMatches(card))

    merged = []
    all = []
    all.extend(applelist)
    all.extend(googlelist)
    for vcard in all:
        match = filter(lambda m: vcard.matches(m), merged)
        if not match:
            merged.append(vcard)
        else:
            match[0].merge(vcard)

            if len(match) > 1:
                if (len(match[0].name & match[1].name) >= 2
                        and len(match) <= 2):
                    match[0].merge(match[1])
                    merged.remove(match[1])
                else:
                    raise Exception(
                        "Length %(l)d > 1, first two elements are %(a)s and %(b)s,"
                        % {
                            "l": len(match),
                            "a": match[0],
                            "b": match[1]
                        })

    import codecs
    f = codecs.open('result.txt', encoding='utf-16', mode='w+')

    try:
        for x in merged:
            if (len(x.name) > 0 and len(x.emails) > 0 and x.apple):

                f.write(
                    unicode(u"%(name)s: %(emails)s\n" % {
                        "name": list(x.name),
                        "emails": list(x.emails)
                    }))

    finally:
        f.close()
예제 #4
0
def main():
	applelist = []
	for x in vobject.readComponents(file("vCard-kort.vcf")):
		card=parsevCard(x)
		card.apple = True
		applelist.append(vCardWithMatches(card))
	
	googlelist = []
	for x in vobject.readComponents(file("contacts.vcf")):
		card = parsevCard(x)
		card.apple = False
		googlelist.append(vCardWithMatches(card))
	

		
	
	merged = []
	all = []
	all.extend(applelist)
	all.extend(googlelist)
	for vcard in all:
		match = filter(lambda m:vcard.matches(m),merged)
		if not match:
			merged.append(vcard)
		else:
			match[0].merge(vcard)
			
			if len(match)>1 :
				if (len( match[0].name & match[1].name )>=2 and len(match)<=2):
					match[0].merge(match[1])
					merged.remove(match[1])
				else:
					raise Exception("Length %(l)d > 1, first two elements are %(a)s and %(b)s,"%{"l":len(match),"a":match[0],"b":match[1]})
	
	
	import codecs
	f = codecs.open('result.txt', encoding='utf-16', mode='w+')
		
	try:
		for x in merged:
			if (len(x.name)>0 and len(x.emails)>0 and x.apple):
				
				f.write(unicode( u"%(name)s: %(emails)s\n"%{"name":list(x.name), "emails":list(x.emails)}))
			
	finally:
	    f.close()
	def testsimilarity(self):
		vcard = vCardWithMatches(vCard(name="rasmus halland"))
		vcard.emails.add("*****@*****.**")
		vcard2 = vCardWithMatches(vCard(name="rasmus lolland"))
		vcard2.emails.add("*****@*****.**")
		self.assertTrue(vcard.matches(vcard2))
예제 #6
0
 def testsimilarity(self):
     vcard = vCardWithMatches(vCard(name="rasmus halland"))
     vcard.emails.add("*****@*****.**")
     vcard2 = vCardWithMatches(vCard(name="rasmus lolland"))
     vcard2.emails.add("*****@*****.**")
     self.assertTrue(vcard.matches(vcard2))