Browse Source

Kleine Korrektur beim Kontaktabgleich

robert 2 years ago
parent
commit
95a4da9226
1 changed files with 11 additions and 12 deletions
  1. 11 12
      contacts/o365_copy.py

+ 11 - 12
contacts/o365_copy.py

@@ -1,5 +1,5 @@
 from O365 import Account
-from O365.address_book import Contact
+from O365.address_book import Contact, Recipients
 
 
 client_id = '925f74dc-f96a-4718-9ca7-d6cc3fa43e1e'
@@ -35,7 +35,9 @@ def copy_contact(p_from: Contact, p_to: Contact):
     p_to.business_phones = p_from.business_phones
     p_to.mobile_phone = p_from.mobile_phone
     p_to.home_phones = p_from.home_phones
-    p_to._Contact__emails = p_from._Contact__emails
+    p_to.emails.clear()
+    for rcp in p_from.emails:
+        p_to.emails.add(rcp)
     p_to.business_address = p_from.business_address
     # p_to.home_address = p_from.home_address
     p_to.other_address = p_from.other_address
@@ -57,14 +59,14 @@ def sync_contacts():
         print(extra_contacts)
         # p.delete()
 
-        for p in shared_contacts.values():
-            if p.display_name not in personal_contacts:
+        for p_shared in shared_contacts.values():
+            if p_shared.display_name not in personal_contacts:
                 p_new = personal.new_contact()
-                copy_contact(p, p_new)
+                copy_contact(p_shared, p_new)
             else:
-                p_existing = personal_contacts[p.display_name]
-                if p.modified > p_existing.modified:
-                    copy_contact(p, p_existing)
+                p_existing = personal_contacts[p_shared.display_name]
+                if p_existing.to_api_data() != p_shared.to_api_data():
+                    copy_contact(p_shared, p_existing)
 
 
 def delete_contacts(delete_candidates):
@@ -110,8 +112,5 @@ def cleanup_contacts():
 
 if __name__ == '__main__':
     sync_contacts()
-    # delete_contacts({'Peugeot Peugeot / Citroen - Hotline'})
+    # delete_contacts({'Matios Yigit', 'Martin Petz', 'Herr Steinraths', 'Herr Fischer'})
     # cleanup_contacts()
-    # gal = account.directory()
-    # mails = [p.mail for p in gal.get_users()]
-    # print(mails)