|
@@ -1,25 +1,22 @@
|
|
|
from O365 import Account
|
|
|
from O365.address_book import Contact
|
|
|
|
|
|
-
|
|
|
-client_id = '925f74dc-f96a-4718-9ca7-d6cc3fa43e1e'
|
|
|
-client_secret = 'SS~8Q~QpBZV9toZuwkzW1XGGen2Hn833spNMtdq5'
|
|
|
+client_id = "925f74dc-f96a-4718-9ca7-d6cc3fa43e1e"
|
|
|
+client_secret = "SS~8Q~QpBZV9toZuwkzW1XGGen2Hn833spNMtdq5"
|
|
|
|
|
|
account = Account(
|
|
|
- (client_id, client_secret),
|
|
|
- auth_flow_type='credentials',
|
|
|
- tenant_id='2ad0dff5-07ce-4cc2-a852-99ce8b91c218'
|
|
|
+ (client_id, client_secret), auth_flow_type="credentials", tenant_id="2ad0dff5-07ce-4cc2-a852-99ce8b91c218"
|
|
|
)
|
|
|
|
|
|
mailboxes = [
|
|
|
- 'bedner@global-cube.net',
|
|
|
- 'brandt@global-cube.net',
|
|
|
+ "winter@global-cube.net",
|
|
|
+ "bedner@global-cube.net",
|
|
|
+ "brandt@global-cube.net",
|
|
|
# 'd.ankenbrand@global-cube.de',
|
|
|
# 'gawliczek@global-cube.de',
|
|
|
- 'm.geiss@global-cube.net',
|
|
|
- 'matarrelli@global-cube.net',
|
|
|
- 'winkler@global-cube.net',
|
|
|
- 'winter@global-cube.de'
|
|
|
+ "m.geiss@global-cube.net",
|
|
|
+ "matarrelli@global-cube.net",
|
|
|
+ "winkler@global-cube.net",
|
|
|
]
|
|
|
|
|
|
|
|
@@ -48,13 +45,13 @@ def copy_contact(p_from: Contact, p_to: Contact):
|
|
|
|
|
|
def sync_contacts():
|
|
|
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)}
|
|
|
delete_candidates = set()
|
|
|
|
|
|
for mailbox in mailboxes:
|
|
|
print(mailbox)
|
|
|
- personal = account.address_book(resource=mailbox, address_book='personal')
|
|
|
+ personal = account.address_book(resource=mailbox, address_book="personal")
|
|
|
personal_contacts = {p.display_name: p for p in personal.get_contacts(limit=None)}
|
|
|
extra_contacts = set(personal_contacts.keys()).difference(shared_contacts.keys())
|
|
|
print(extra_contacts)
|
|
@@ -80,7 +77,7 @@ def delete_contacts(delete_candidates):
|
|
|
|
|
|
for mailbox in mailboxes:
|
|
|
print(mailbox)
|
|
|
- personal = account.address_book(resource=mailbox, address_book='personal')
|
|
|
+ personal = account.address_book(resource=mailbox, address_book="personal")
|
|
|
personal_contacts = {p.display_name: p for p in personal.get_contacts(limit=None)}
|
|
|
|
|
|
selected_contacts = set(delete_candidates).intersection(personal_contacts.keys())
|
|
@@ -92,16 +89,16 @@ def delete_contacts(delete_candidates):
|
|
|
def normalize_phone_number(phone_number: str):
|
|
|
if phone_number is None:
|
|
|
return None
|
|
|
- if phone_number.startswith('0'):
|
|
|
- phone_number = '+49 ' + phone_number[1:]
|
|
|
- for c in '()/?':
|
|
|
- phone_number = phone_number.replace(c, '')
|
|
|
- return phone_number.replace(' -', '-').replace('- ', '-').replace(' ', ' ')
|
|
|
+ if phone_number.startswith("0"):
|
|
|
+ phone_number = "+49 " + phone_number[1:]
|
|
|
+ for c in "()/?":
|
|
|
+ phone_number = phone_number.replace(c, "")
|
|
|
+ return phone_number.replace(" -", "-").replace("- ", "-").replace(" ", " ")
|
|
|
|
|
|
|
|
|
def cleanup_contacts():
|
|
|
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")
|
|
|
|
|
|
for p in shared.get_contacts(limit=None):
|
|
|
business = [normalize_phone_number(no) for no in p.business_phones]
|
|
@@ -116,7 +113,7 @@ def cleanup_contacts():
|
|
|
p.save()
|
|
|
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
+if __name__ == "__main__":
|
|
|
contacts = sync_contacts()
|
|
|
if len(contacts) > 0:
|
|
|
delete_contacts(contacts)
|