mbu-dev-shared-components 0.0.49__tar.gz → 0.0.51.post3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/PKG-INFO +2 -3
  2. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/README.md +0 -1
  3. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/documents.py +32 -1
  4. {mbu_dev_shared_components-0.0.49/mbu_dev_shared_components/office365 → mbu_dev_shared_components-0.0.51.post3/mbu_dev_shared_components/msoffice365}/sharepoint_api/files.py +83 -29
  5. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components.egg-info/PKG-INFO +2 -3
  6. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components.egg-info/SOURCES.txt +5 -5
  7. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components.egg-info/requires.txt +1 -1
  8. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/pyproject.toml +2 -2
  9. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/.github/workflows/pylint.yml +0 -0
  10. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/.gitignore +0 -0
  11. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/.pylintrc +0 -0
  12. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/LICENSE +0 -0
  13. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/__init__.py +0 -0
  14. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/auth.py +0 -0
  15. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/cases.py +0 -0
  16. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/contacts.py +0 -0
  17. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/getorganized/objects.py +0 -0
  18. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/google/__init__.py +0 -0
  19. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/google/api/__init__.py +0 -0
  20. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/google/api/auth.py +0 -0
  21. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/google/workspace/__init__.py +0 -0
  22. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/google/workspace/alerts.py +0 -0
  23. {mbu_dev_shared_components-0.0.49/mbu_dev_shared_components/office365 → mbu_dev_shared_components-0.0.51.post3/mbu_dev_shared_components/msoffice365}/__init__.py +0 -0
  24. {mbu_dev_shared_components-0.0.49/mbu_dev_shared_components/office365 → mbu_dev_shared_components-0.0.51.post3/mbu_dev_shared_components/msoffice365}/excel/__init__.py +0 -0
  25. {mbu_dev_shared_components-0.0.49/mbu_dev_shared_components/office365 → mbu_dev_shared_components-0.0.51.post3/mbu_dev_shared_components/msoffice365}/excel/excel_reader.py +0 -0
  26. {mbu_dev_shared_components-0.0.49/mbu_dev_shared_components/office365 → mbu_dev_shared_components-0.0.51.post3/mbu_dev_shared_components/msoffice365}/sharepoint_api/__init__.py +0 -0
  27. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/os2forms/__init__.py +0 -0
  28. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/os2forms/documents.py +0 -0
  29. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/os2forms/forms.py +0 -0
  30. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/sap/__init__.py +0 -0
  31. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/sap/create_invoice.py +0 -0
  32. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/utils/__init__.py +0 -0
  33. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/utils/db_stored_procedure_executor.py +0 -0
  34. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/utils/fernet_encryptor.py +0 -0
  35. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components/utils/json_handler.py +0 -0
  36. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components.egg-info/dependency_links.txt +0 -0
  37. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/mbu_dev_shared_components.egg-info/top_level.txt +0 -0
  38. {mbu_dev_shared_components-0.0.49 → mbu_dev_shared_components-0.0.51.post3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mbu_dev_shared_components
3
- Version: 0.0.49
3
+ Version: 0.0.51.post3
4
4
  Summary: Shared components to use in RPA projects
5
5
  Author-email: MBU <rpa@mbu.aarhus.dk>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -9,12 +9,12 @@ Classifier: Operating System :: Microsoft :: Windows
9
9
  Requires-Python: >=3.7
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
- Requires-Dist: shareplum
13
12
  Requires-Dist: openpyxl>=3.1.2
14
13
  Requires-Dist: pyodbc>=5.1.0
15
14
  Requires-Dist: requests_ntlm>=1.2.0
16
15
  Requires-Dist: python-dateutil==2.9.*
17
16
  Requires-Dist: cryptography>=43.0.0
17
+ Requires-Dist: office365-rest-python-client
18
18
 
19
19
  # mbu-dev-shared-components
20
20
 
@@ -60,7 +60,6 @@ Additionally, it provides functionalities to count the total number of rows and
60
60
  #### - Invoices
61
61
 
62
62
  This module provides the InvoiceCreator class to create invoices in SAP.
63
-
64
63
  The InvoiceCreator class offers methods to open a specified business partner, and creat an invoice.
65
64
 
66
65
  - Open business partner
@@ -42,7 +42,6 @@ Additionally, it provides functionalities to count the total number of rows and
42
42
  #### - Invoices
43
43
 
44
44
  This module provides the InvoiceCreator class to create invoices in SAP.
45
-
46
45
  The InvoiceCreator class offers methods to open a specified business partner, and creat an invoice.
47
46
 
48
47
  - Open business partner
@@ -46,7 +46,38 @@ def mark_file_as_case_record(documents_id: list, api_endpoint: str, api_username
46
46
  """
47
47
  headers = {'Content-Type': 'application/json'}
48
48
  payload = {"DocumentIds": documents_id}
49
- print(payload)
49
+
50
+ response = requests.request(method='POST', url=api_endpoint, headers=headers, json=payload, auth=get_ntlm_go_api_credentials(api_username, api_password), timeout=60)
51
+ response.raise_for_status()
52
+
53
+ return response
54
+
55
+
56
+ def finalize_file(documents_id: list, api_endpoint: str, api_username: str, api_password: str) -> requests.Response:
57
+ """
58
+ Marks one or more documents by their IDs as finalized in the system via a POST request to a specific API endpoint.
59
+ This operation modifies the status of the documents to reflect their new role as finalized case records.
60
+ The function constructs the JSON payload by encapsulating the document IDs within a list under the 'DocumentIds' key.
61
+
62
+ Parameters:
63
+ documents_id (list): A list of integers representing document IDs that should be marked as case records.
64
+ api_endpoint (str): GetOrganized API endpoint.
65
+ api_username (str): The API username for GetOrganized API.
66
+ api_password (str): The API password for GetOrganized API.
67
+
68
+ Returns:
69
+ Dict[str, Any]: The JSON response from the API, which includes the status of the operation and potentially updated document details.
70
+
71
+ Raises:
72
+ requests.RequestException: If the HTTP request fails for any reason.
73
+ """
74
+ headers = {'Content-Type': 'application/json'}
75
+ payload = {
76
+ "DocumentIds": documents_id,
77
+ "ShouldCloseOpenTasks": False
78
+ }
79
+
50
80
  response = requests.request(method='POST', url=api_endpoint, headers=headers, json=payload, auth=get_ntlm_go_api_credentials(api_username, api_password), timeout=60)
81
+ response.raise_for_status()
51
82
 
52
83
  return response
@@ -30,15 +30,16 @@ Example:
30
30
  """
31
31
 
32
32
  from pathlib import PurePath
33
- from typing import Optional
34
- from shareplum import Site, Office365
35
- from shareplum.site import Version
33
+ from typing import Optional, List
34
+ import os
35
+ from office365.runtime.auth.user_credential import UserCredential
36
+ from office365.sharepoint.client_context import ClientContext
36
37
 
37
38
 
38
39
  class Sharepoint:
39
40
  """
40
41
  A class to interact with a SharePoint site, enabling authentication, file listing,
41
- downloading, and saving functionalities within a specified SharePoint document library.
42
+ downloading, uploading, and saving functionalities within a specified SharePoint document library.
42
43
 
43
44
  Attributes:
44
45
  username (str): Username for authentication.
@@ -48,32 +49,36 @@ class Sharepoint:
48
49
  document_library (str): Document library path.
49
50
  """
50
51
 
51
- def __init__(self, username: str, password: str, site_url: str, site_name: str, document_library: str):
52
+ def __init__(
53
+ self, username: str, password: str, site_url: str, site_name: str, document_library: str
54
+ ):
52
55
  """Initializes the Sharepoint class with credentials and site details."""
53
56
  self.username = username
54
57
  self.password = password
55
58
  self.site_url = site_url
56
59
  self.site_name = site_name
57
60
  self.document_library = document_library
58
- self.site = self._auth()
61
+ self.ctx = self._auth()
59
62
 
60
- def _auth(self) -> Optional[Site]:
63
+ def _auth(self) -> Optional[ClientContext]:
61
64
  """
62
- Authenticates to the SharePoint site and returns the site object.
65
+ Authenticates to the SharePoint site and returns the client context.
63
66
 
64
67
  Returns:
65
- Optional[Site]: A SharePlum Site object for interacting with the SharePoint site if authentication is successful,
68
+ Optional[ClientContext]: A ClientContext object for interacting with the SharePoint site if authentication is successful,
66
69
  otherwise None.
67
70
  """
68
71
  try:
69
- authcookie = Office365(self.site_url, username=self.username, password=self.password).GetCookies()
70
- site = Site(f'{self.site_url}/sites/{self.site_name}', version=Version.v365, authcookie=authcookie)
71
- return site
72
+ site_full_url = f"{self.site_url}/teams/{self.site_name}"
73
+ ctx = ClientContext(site_full_url).with_credentials(
74
+ UserCredential(self.username, self.password)
75
+ )
76
+ return ctx
72
77
  except Exception as e:
73
78
  print(f"Failed to authenticate: {e}")
74
79
  return None
75
80
 
76
- def fetch_files_list(self, folder_name: str) -> Optional[list]:
81
+ def fetch_files_list(self, folder_name: str) -> Optional[List[dict]]:
77
82
  """
78
83
  Retrieves a list of files from a specified folder within the document library.
79
84
 
@@ -81,13 +86,17 @@ class Sharepoint:
81
86
  folder_name (str): The name of the folder within the document library.
82
87
 
83
88
  Returns:
84
- list: A list of file dictionaries in the specified folder, or an empty list if an error occurs or if the site is not authenticated.
89
+ list: A list of file dictionaries in the specified folder, or None if an error occurs or if the site is not authenticated.
85
90
  """
86
- if self.site:
91
+ if self.ctx:
87
92
  try:
88
- folder = self.site.Folder(f'{self.document_library}/{folder_name}')
93
+ folder_url = f"/teams/{self.site_name}/{self.document_library}/{folder_name}"
94
+ folder = self.ctx.web.get_folder_by_server_relative_url(folder_url)
89
95
  files = folder.files
90
- return files
96
+ self.ctx.load(files)
97
+ self.ctx.execute_query()
98
+ files_list = [{"Name": file.name} for file in files]
99
+ return files_list
91
100
  except Exception as e:
92
101
  print(f"Error retrieving files: {e}")
93
102
  return None
@@ -102,13 +111,14 @@ class Sharepoint:
102
111
  folder_name (str): The name of the folder where the file is located.
103
112
 
104
113
  Returns:
105
- bytes (Optional): The binary content of the file if successful, otherwise None.
114
+ Optional[bytes]: The binary content of the file if successful, otherwise None.
106
115
  """
107
- if self.site:
116
+ if self.ctx:
108
117
  try:
109
- folder = self.site.Folder(f'{self.document_library}/{folder_name}')
110
- file_content = folder.get_file(file_name)
111
- return file_content
118
+ file_url = f"/teams/{self.site_name}/{self.document_library}/{folder_name}/{file_name}"
119
+ file = self.ctx.web.get_file_by_server_relative_url(file_url)
120
+ file_content = file.read().execute_query()
121
+ return file_content.value
112
122
  except Exception as e:
113
123
  print(f"Failed to download file: {e}")
114
124
  return None
@@ -124,7 +134,7 @@ class Sharepoint:
124
134
  file_content (bytes): The binary content of the file.
125
135
  """
126
136
  file_directory_path = PurePath(folder_destination, file_name)
127
- with open(file_directory_path, 'wb') as file:
137
+ with open(file_directory_path, "wb") as file:
128
138
  file.write(file_content)
129
139
 
130
140
  def download_file(self, folder: str, filename: str, folder_destination: str):
@@ -151,9 +161,53 @@ class Sharepoint:
151
161
  folder_destination (str): The local folder path where the downloaded files will be saved.
152
162
  """
153
163
  files_list = self.fetch_files_list(folder)
154
- for file in files_list:
155
- file_content = self.fetch_file_content(file['Name'], folder)
156
- if file_content:
157
- self._write_file(folder_destination, file['Name'], file_content)
158
- else:
159
- print(f"Failed to download {file['Name']}")
164
+ if files_list:
165
+ for file in files_list:
166
+ file_content = self.fetch_file_content(file["Name"], folder)
167
+ if file_content:
168
+ self._write_file(folder_destination, file["Name"], file_content)
169
+ else:
170
+ print(f"Failed to download {file['Name']}")
171
+ else:
172
+ print(f"No files found in folder {folder}")
173
+
174
+ def upload_file(self, folder_name: str, file_path: str, file_name: Optional[str] = None):
175
+ """
176
+ Uploads a single file to a specified folder within the document library.
177
+
178
+ Args:
179
+ folder_name (str): The name of the folder within the document library.
180
+ file_path (str): The local path to the file to be uploaded.
181
+ file_name (Optional[str]): The name to give the file in SharePoint. If not provided, uses the name from file_path.
182
+ """
183
+ if self.ctx:
184
+ try:
185
+ if file_name is None:
186
+ file_name = os.path.basename(file_path)
187
+
188
+ folder_url = f"/teams/{self.site_name}/{self.document_library}/{folder_name}"
189
+ target_folder = self.ctx.web.get_folder_by_server_relative_url(folder_url)
190
+
191
+ with open(file_path, 'rb') as content_file:
192
+ file_content = content_file.read()
193
+
194
+ target_folder.upload_file(file_name, file_content).execute_query()
195
+ print(f"File '{file_name}' uploaded successfully to '{folder_url}'.")
196
+ except Exception as e:
197
+ print(f"Failed to upload file '{file_name}': {e}")
198
+
199
+ def upload_files(self, folder_name: str, files: List[str]):
200
+ """
201
+ Uploads multiple files to a specified folder within the document library.
202
+
203
+ Args:
204
+ folder_name (str): The name of the folder within the document library.
205
+ files (List[str]): A list of local file paths to be uploaded.
206
+ """
207
+ if self.ctx:
208
+ for file_path in files:
209
+ try:
210
+ file_name = os.path.basename(file_path)
211
+ self.upload_file(folder_name, file_path, file_name)
212
+ except Exception as e:
213
+ print(f"Failed to upload file '{file_path}': {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mbu_dev_shared_components
3
- Version: 0.0.49
3
+ Version: 0.0.51.post3
4
4
  Summary: Shared components to use in RPA projects
5
5
  Author-email: MBU <rpa@mbu.aarhus.dk>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -9,12 +9,12 @@ Classifier: Operating System :: Microsoft :: Windows
9
9
  Requires-Python: >=3.7
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
- Requires-Dist: shareplum
13
12
  Requires-Dist: openpyxl>=3.1.2
14
13
  Requires-Dist: pyodbc>=5.1.0
15
14
  Requires-Dist: requests_ntlm>=1.2.0
16
15
  Requires-Dist: python-dateutil==2.9.*
17
16
  Requires-Dist: cryptography>=43.0.0
17
+ Requires-Dist: office365-rest-python-client
18
18
 
19
19
  # mbu-dev-shared-components
20
20
 
@@ -60,7 +60,6 @@ Additionally, it provides functionalities to count the total number of rows and
60
60
  #### - Invoices
61
61
 
62
62
  This module provides the InvoiceCreator class to create invoices in SAP.
63
-
64
63
  The InvoiceCreator class offers methods to open a specified business partner, and creat an invoice.
65
64
 
66
65
  - Open business partner
@@ -20,11 +20,11 @@ mbu_dev_shared_components/google/api/__init__.py
20
20
  mbu_dev_shared_components/google/api/auth.py
21
21
  mbu_dev_shared_components/google/workspace/__init__.py
22
22
  mbu_dev_shared_components/google/workspace/alerts.py
23
- mbu_dev_shared_components/office365/__init__.py
24
- mbu_dev_shared_components/office365/excel/__init__.py
25
- mbu_dev_shared_components/office365/excel/excel_reader.py
26
- mbu_dev_shared_components/office365/sharepoint_api/__init__.py
27
- mbu_dev_shared_components/office365/sharepoint_api/files.py
23
+ mbu_dev_shared_components/msoffice365/__init__.py
24
+ mbu_dev_shared_components/msoffice365/excel/__init__.py
25
+ mbu_dev_shared_components/msoffice365/excel/excel_reader.py
26
+ mbu_dev_shared_components/msoffice365/sharepoint_api/__init__.py
27
+ mbu_dev_shared_components/msoffice365/sharepoint_api/files.py
28
28
  mbu_dev_shared_components/os2forms/__init__.py
29
29
  mbu_dev_shared_components/os2forms/documents.py
30
30
  mbu_dev_shared_components/os2forms/forms.py
@@ -1,6 +1,6 @@
1
- shareplum
2
1
  openpyxl>=3.1.2
3
2
  pyodbc>=5.1.0
4
3
  requests_ntlm>=1.2.0
5
4
  python-dateutil==2.9.*
6
5
  cryptography>=43.0.0
6
+ office365-rest-python-client
@@ -17,12 +17,12 @@ classifiers = [
17
17
  "Operating System :: Microsoft :: Windows",
18
18
  ]
19
19
  dependencies = [
20
- "shareplum",
21
20
  "openpyxl >= 3.1.2",
22
21
  "pyodbc >= 5.1.0",
23
22
  "requests_ntlm >= 1.2.0",
24
23
  "python-dateutil == 2.9.*",
25
- "cryptography >= 43.0.0"
24
+ "cryptography >= 43.0.0",
25
+ "office365-rest-python-client",
26
26
  ]
27
27
 
28
28
  [tool.setuptools_scm]