I have two vcards :
vcard1 = "BEGIN:VCARD
          VERSION:3.0
          N;CHARSET=UTF-8:Name;;;;
          TEL:0005555000
          END:VCARD"
vcard2 = "BEGIN:VCARD
      VERSION:3.0
      N;CHARSET=UTF-8:Name;;;;
      TEL:0005555000
      EMAIL;CHARSET=UTF-8:[email protected]
      END:VCARD"
As you can see the only difference is that the second vcard has an additional attribute which is EMAIL? Are these two vcards could be considered as equal using code ?
import vobject
print(vobject.readOne(vcard1).serialize()==vobject.readOne(vcard2).serialize())
				
                        
Solution
The first rule for any comparison is to define the basis of comparison. You can even compare apples and oranges, provided you are looking for a quantity that can be compared: such as "how many apples vs. oranges" or "weight of 5-apples vs. 5-oranges". The point being the definition of underlying basis of comparison must be unambiguous.
Extending this concept to your use-case, you can compare the
vcardsagainst each field and then also compare against all fields. For example, I have shown you three ways to compare them:Example A1: compare only commmon fileds betweenvcard1andvcard2.Example A2: compare all fileds betweenvcard1andvcard2.Example A3: compare only commmon user-specified fileds betweenvcard1andvcard2.Obviously, in this case if you compare the serialized versions of
vcard1andvcard2, it would returnFalseas the content of these two vcards are different.Example
In each case (
A1, A2, A3), the custom functioncompare_vcards()returns two things:match: adict, giving matches at each field's levelsummary: adict, giving aggregated absolute match (if all fields matched) and relative (scale:[0,1]) matches (good for partial match).Code
Dummy Data
References