From a6aa563bb75cb40712b0e1b85a18ccbf54e26b3b Mon Sep 17 00:00:00 2001 From: Philippe Lamprecht Date: Wed, 25 Sep 2024 19:50:22 +0200 Subject: [PATCH] initial commit, updated requirements.txt, initial design --- requirements.txt | Bin 1060 -> 1056 bytes sharepoint.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 sharepoint.py diff --git a/requirements.txt b/requirements.txt index 81c085819e77a259a8e1a0675021136e1310f93d..70e02bc4a64d2525ae0733e76a6cd0e9c4ad0763 100644 GIT binary patch delta 74 zcmZ3&v4CU41V%=a$rBl!nT;9DHeY8V$rBl!nT;4MHeY8V!Z diff --git a/sharepoint.py b/sharepoint.py new file mode 100644 index 0000000..83b7229 --- /dev/null +++ b/sharepoint.py @@ -0,0 +1,48 @@ +"""module to sync files with sharepoint site""" + +from O365 import Account +from decouple import config + + +class _sharepoint: + def __init__(self) -> None: + client_id = config("CLIENTID") + client_secret = config("CLIENTSECRET") + tenant_id = config("TENANTID") + account = self._authenticate(client_id, client_secret, tenant_id) + self.storage = account.storage() + + def _authenticate(self, client_id: str, client_secret: str, tenant_id: str): + """authenticate with Micosoft Graph API + + Args: + client_id (str): microsoft client id + client_secret (str): microsoft client secret + tenant_id (str): microsoft tenant id + + Returns: + account: O365 account object if authentication was successful + """ + credentials = (client_id, client_secret) + try: + account = Account( + credentials, auth_flow_type="credentials", tenant_id=tenant_id + ) + if account.authenticate(): + print("Authenticated!") + return account + except ValueError as e: + print(e) + return None + + def download_file(self): + """_summary_""" + # File to download, and location to download to + dl_path = "/path/to/download" + f_name = "myfile.xlsx" + + def upload_file(self): + """_summary_""" + # File to upload, and location to upload to + ul_path = "/path/to/upload" + f_name = "myfile.xlsx"