|
@@ -1,5 +1,5 @@
|
|
from O365 import Account
|
|
from O365 import Account
|
|
-from O365.address_book import Contact, Recipients
|
|
|
|
|
|
+from O365.address_book import Contact
|
|
|
|
|
|
|
|
|
|
client_id = '925f74dc-f96a-4718-9ca7-d6cc3fa43e1e'
|
|
client_id = '925f74dc-f96a-4718-9ca7-d6cc3fa43e1e'
|
|
@@ -50,6 +50,7 @@ def sync_contacts():
|
|
account.authenticate()
|
|
account.authenticate()
|
|
shared = account.address_book(resource='adressbuch@global-cube.net', address_book='personal')
|
|
shared = account.address_book(resource='adressbuch@global-cube.net', address_book='personal')
|
|
shared_contacts = {p.display_name: p for p in shared.get_contacts(limit=None)}
|
|
shared_contacts = {p.display_name: p for p in shared.get_contacts(limit=None)}
|
|
|
|
+ delete_candidates = set()
|
|
|
|
|
|
for mailbox in mailboxes:
|
|
for mailbox in mailboxes:
|
|
print(mailbox)
|
|
print(mailbox)
|
|
@@ -57,6 +58,10 @@ def sync_contacts():
|
|
personal_contacts = {p.display_name: p for p in personal.get_contacts(limit=None)}
|
|
personal_contacts = {p.display_name: p for p in personal.get_contacts(limit=None)}
|
|
extra_contacts = set(personal_contacts.keys()).difference(shared_contacts.keys())
|
|
extra_contacts = set(personal_contacts.keys()).difference(shared_contacts.keys())
|
|
print(extra_contacts)
|
|
print(extra_contacts)
|
|
|
|
+ if len(delete_candidates) == 0:
|
|
|
|
+ delete_candidates = extra_contacts
|
|
|
|
+ else:
|
|
|
|
+ delete_candidates = delete_candidates.intersection(extra_contacts)
|
|
# p.delete()
|
|
# p.delete()
|
|
|
|
|
|
for p_shared in shared_contacts.values():
|
|
for p_shared in shared_contacts.values():
|
|
@@ -67,6 +72,7 @@ def sync_contacts():
|
|
p_existing = personal_contacts[p_shared.display_name]
|
|
p_existing = personal_contacts[p_shared.display_name]
|
|
if p_existing.to_api_data() != p_shared.to_api_data():
|
|
if p_existing.to_api_data() != p_shared.to_api_data():
|
|
copy_contact(p_shared, p_existing)
|
|
copy_contact(p_shared, p_existing)
|
|
|
|
+ return delete_candidates
|
|
|
|
|
|
|
|
|
|
def delete_contacts(delete_candidates):
|
|
def delete_contacts(delete_candidates):
|
|
@@ -111,6 +117,7 @@ def cleanup_contacts():
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
- sync_contacts()
|
|
|
|
- # delete_contacts({'Matios Yigit', 'Martin Petz', 'Herr Steinraths', 'Herr Fischer'})
|
|
|
|
|
|
+ contacts = sync_contacts()
|
|
|
|
+ if len(contacts) > 0:
|
|
|
|
+ delete_contacts(contacts)
|
|
# cleanup_contacts()
|
|
# cleanup_contacts()
|