rpa-suite 1.6.1__py3-none-any.whl → 1.6.3__py3-none-any.whl
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.
- rpa_suite/__init__.py +1 -1
- rpa_suite/core/__init__.py +5 -1
- rpa_suite/core/artemis.py +445 -0
- rpa_suite/core/asyncrun.py +15 -8
- rpa_suite/core/browser.py +44 -41
- rpa_suite/core/clock.py +46 -13
- rpa_suite/core/date.py +41 -16
- rpa_suite/core/dir.py +29 -72
- rpa_suite/core/email.py +26 -15
- rpa_suite/core/file.py +46 -43
- rpa_suite/core/iris.py +146 -70
- rpa_suite/core/log.py +134 -46
- rpa_suite/core/parallel.py +185 -182
- rpa_suite/core/print.py +119 -96
- rpa_suite/core/regex.py +26 -26
- rpa_suite/core/validate.py +20 -76
- rpa_suite/functions/__init__.py +1 -1
- rpa_suite/suite.py +13 -1
- rpa_suite/utils/__init__.py +1 -1
- rpa_suite/utils/system.py +64 -61
- {rpa_suite-1.6.1.dist-info → rpa_suite-1.6.3.dist-info}/METADATA +8 -18
- rpa_suite-1.6.3.dist-info/RECORD +27 -0
- rpa_suite-1.6.1.dist-info/RECORD +0 -26
- {rpa_suite-1.6.1.dist-info → rpa_suite-1.6.3.dist-info}/WHEEL +0 -0
- {rpa_suite-1.6.1.dist-info → rpa_suite-1.6.3.dist-info}/licenses/LICENSE +0 -0
- {rpa_suite-1.6.1.dist-info → rpa_suite-1.6.3.dist-info}/top_level.txt +0 -0
rpa_suite/core/email.py
CHANGED
@@ -9,8 +9,12 @@ from email.mime.base import MIMEBase
|
|
9
9
|
from email import encoders
|
10
10
|
|
11
11
|
# imports internal
|
12
|
-
from rpa_suite.functions._printer import
|
12
|
+
from rpa_suite.functions._printer import success_print
|
13
13
|
|
14
|
+
class EmailError(Exception):
|
15
|
+
"""Custom exception for Email errors."""
|
16
|
+
def __init__(self, message):
|
17
|
+
super().__init__(f'EmailError: {message}')
|
14
18
|
|
15
19
|
class Email:
|
16
20
|
"""
|
@@ -80,7 +84,14 @@ class Email:
|
|
80
84
|
body_message: str = "<p>Testing message body</p>"
|
81
85
|
auth_tls: bool = (False,)
|
82
86
|
|
83
|
-
def __init__(self):
|
87
|
+
def __init__(self) -> None:
|
88
|
+
"""
|
89
|
+
Constructor function for the Email class that provides utilities for email management.
|
90
|
+
|
91
|
+
This class offers functionalities for sending emails via SMTP protocol with support
|
92
|
+
for attachments, HTML formatting, and various SMTP server configurations.
|
93
|
+
"""
|
94
|
+
pass
|
84
95
|
|
85
96
|
def send_smtp(
|
86
97
|
self,
|
@@ -93,7 +104,7 @@ class Email:
|
|
93
104
|
smtp_server: str = "smtp.hostinger.com",
|
94
105
|
smtp_port: str = 465,
|
95
106
|
auth_tls: bool = False,
|
96
|
-
|
107
|
+
verbose: bool = True,
|
97
108
|
):
|
98
109
|
"""
|
99
110
|
Sends an email using the specified SMTP server.
|
@@ -158,17 +169,17 @@ class Email:
|
|
158
169
|
self.attachments = attachments
|
159
170
|
self.auth_tls = auth_tls
|
160
171
|
|
161
|
-
#
|
172
|
+
# Creating the message
|
162
173
|
msg = MIMEMultipart()
|
163
174
|
msg["From"] = self.email_user
|
164
175
|
msg["To"] = ", ".join(self.email_to) if isinstance(self.email_to, list) else self.email_to
|
165
176
|
msg["Subject"] = str(self.subject_title)
|
166
177
|
|
167
|
-
#
|
178
|
+
# Email body
|
168
179
|
body = str(self.body_message)
|
169
180
|
msg.attach(MIMEText(body, "html"))
|
170
181
|
|
171
|
-
#
|
182
|
+
# Attachments (optional)
|
172
183
|
if self.attachments:
|
173
184
|
for attachment_path in self.attachments:
|
174
185
|
try:
|
@@ -183,29 +194,29 @@ class Email:
|
|
183
194
|
msg.attach(part)
|
184
195
|
|
185
196
|
except Exception as e:
|
186
|
-
|
197
|
+
EmailError(f"Error attaching file {attachment_path}: {str(e)}")
|
187
198
|
|
188
199
|
try:
|
189
200
|
if self.auth_tls:
|
190
|
-
#
|
201
|
+
# Connecting to SMTP server with TLS
|
191
202
|
server = smtplib.SMTP(self.smtp_server, self.smtp_port)
|
192
203
|
server.starttls()
|
193
204
|
server.login(self.email_user, self.email_password)
|
194
205
|
else:
|
195
|
-
#
|
206
|
+
# Connecting to SMTP server with SSL
|
196
207
|
server = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)
|
197
208
|
server.login(self.email_user, self.email_password)
|
198
209
|
|
199
|
-
#
|
210
|
+
# Sending the email
|
200
211
|
server.sendmail(self.email_user, self.email_to, msg.as_string())
|
201
|
-
if
|
202
|
-
success_print("
|
212
|
+
if verbose:
|
213
|
+
success_print("Email sent successfully!")
|
203
214
|
|
204
|
-
#
|
215
|
+
# Closing the connection
|
205
216
|
server.quit()
|
206
217
|
|
207
218
|
except Exception as e:
|
208
|
-
|
219
|
+
EmailError(f"Failed to send email: {str(e)}")
|
209
220
|
|
210
221
|
except Exception as e:
|
211
|
-
|
222
|
+
EmailError(f"A general error occurred in the sendmail function: {str(e)}")
|
rpa_suite/core/file.py
CHANGED
@@ -9,9 +9,13 @@ from typing import Dict, List, Union
|
|
9
9
|
from colorama import Fore
|
10
10
|
|
11
11
|
# imports internal
|
12
|
-
from rpa_suite.functions._printer import
|
12
|
+
from rpa_suite.functions._printer import success_print, alert_print
|
13
13
|
from rpa_suite.functions.__create_ss_dir import __create_ss_dir as create_ss_dir
|
14
14
|
|
15
|
+
class FileError(Exception):
|
16
|
+
"""Custom exception for File errors."""
|
17
|
+
def __init__(self, message):
|
18
|
+
super().__init__(f'FileError: {message}')
|
15
19
|
|
16
20
|
class File:
|
17
21
|
"""
|
@@ -65,7 +69,11 @@ class File:
|
|
65
69
|
"""
|
66
70
|
|
67
71
|
def __init__(self):
|
68
|
-
|
72
|
+
"""Initialize the File class."""
|
73
|
+
try:
|
74
|
+
self.__create_ss_dir = create_ss_dir
|
75
|
+
except Exception as e:
|
76
|
+
raise FileError(f"Error trying execute: {self.__init__.__name__}! {str(e)}.")
|
69
77
|
|
70
78
|
def screen_shot(
|
71
79
|
self,
|
@@ -75,7 +83,7 @@ class File:
|
|
75
83
|
delay: int = 1,
|
76
84
|
use_default_path_and_name: bool = True,
|
77
85
|
name_ss_dir: str | None = None,
|
78
|
-
|
86
|
+
verbose: bool = False,
|
79
87
|
) -> str | None:
|
80
88
|
"""
|
81
89
|
Function responsible for create a dir for screenshot, and file screenshot and save this in dir to create, if dir exists save it on original dir. By default uses date on file name. \n
|
@@ -88,7 +96,7 @@ class File:
|
|
88
96
|
``delay: int`` - should be a int, by default 1 (represents seconds).
|
89
97
|
``use_default_path_and_name: bool`` - should be a boolean, by default `True`
|
90
98
|
``name_ss_dir: str`` - should be a string, by default type `None`
|
91
|
-
``
|
99
|
+
``verbose`` - should be a boolean, by default `False`
|
92
100
|
|
93
101
|
Return:
|
94
102
|
----------
|
@@ -97,22 +105,22 @@ class File:
|
|
97
105
|
|
98
106
|
Description: pt-br
|
99
107
|
----------
|
100
|
-
|
108
|
+
Function responsible for creating a screenshot directory, and screenshot file and saving it in the directory to be created, if the directory exists, save it in the original directory. By default, uses date in the file name.
|
101
109
|
|
102
|
-
|
110
|
+
Parameters:
|
103
111
|
----------
|
104
|
-
``file_name: str`` -
|
105
|
-
``file_path: str`` -
|
106
|
-
``save_with_date: bool`` -
|
107
|
-
``delay: int`` -
|
108
|
-
``use_default_path_and_name: bool`` -
|
109
|
-
``name_ss_dir: str`` -
|
110
|
-
``
|
111
|
-
|
112
|
-
|
112
|
+
``file_name: str`` - should be a string, by default the name is `screenshot`.
|
113
|
+
``file_path: str`` - should be a string, has no default path.
|
114
|
+
``save_with_date: bool`` - should be a boolean, by default `True` saves the file name with date `foo_dd_mm_yyyy-hh_mm_ss.png`.
|
115
|
+
``delay: int`` - should be an int, by default 1 represented in second(s).
|
116
|
+
``use_default_path_and_name: bool`` - should be a boolean, by default `True`
|
117
|
+
``name_ss_dir: str`` - should be a string, by default of type `None`
|
118
|
+
``verbose`` - should be a boolean, by default `False`
|
119
|
+
|
120
|
+
Return:
|
113
121
|
----------
|
114
|
-
>>>
|
115
|
-
* 'screenshot_path': str -
|
122
|
+
>>> type: str
|
123
|
+
* 'screenshot_path': str - represents the absolute path of the created file
|
116
124
|
"""
|
117
125
|
|
118
126
|
# proccess
|
@@ -143,9 +151,8 @@ class File:
|
|
143
151
|
|
144
152
|
image.save(path_file_screenshoted)
|
145
153
|
|
146
|
-
if
|
154
|
+
if verbose:
|
147
155
|
success_print(path_file_screenshoted)
|
148
|
-
|
149
156
|
return path_file_screenshoted
|
150
157
|
|
151
158
|
else: # not use date on file name
|
@@ -155,24 +162,21 @@ class File:
|
|
155
162
|
|
156
163
|
image.save(path_file_screenshoted)
|
157
164
|
|
158
|
-
if
|
165
|
+
if verbose:
|
159
166
|
success_print(path_file_screenshoted)
|
160
|
-
|
161
167
|
return path_file_screenshoted
|
162
168
|
|
163
169
|
except Exception as e:
|
164
|
-
|
165
|
-
error_print(f"Error to execute function:{self.screen_shot.__name__}! Error: {str(e)}")
|
166
|
-
return None
|
170
|
+
FileError(f"Error to execute function:{self.screen_shot.__name__}! Error: {str(e)}")
|
167
171
|
|
168
172
|
def flag_create(
|
169
173
|
self,
|
170
174
|
name_file: str = "running.flag",
|
171
175
|
path_to_create: str | None = None,
|
172
|
-
|
176
|
+
verbose: bool = True,
|
173
177
|
) -> None:
|
174
178
|
"""
|
175
|
-
|
179
|
+
Creates a flag file indicating that the robot is running.
|
176
180
|
"""
|
177
181
|
|
178
182
|
try:
|
@@ -184,20 +188,20 @@ class File:
|
|
184
188
|
|
185
189
|
with open(full_path_with_name, "w", encoding="utf-8") as file:
|
186
190
|
file.write("[RPA Suite] - Running Flag File")
|
187
|
-
if
|
191
|
+
if verbose:
|
188
192
|
success_print("Flag file created.")
|
189
193
|
|
190
194
|
except Exception as e:
|
191
|
-
|
195
|
+
FileError(f"Error in function file_scheduling_create: {str(e)}")
|
192
196
|
|
193
197
|
def flag_delete(
|
194
198
|
self,
|
195
199
|
name_file: str = "running.flag",
|
196
200
|
path_to_delete: str | None = None,
|
197
|
-
|
201
|
+
verbose: bool = True,
|
198
202
|
) -> None:
|
199
203
|
"""
|
200
|
-
|
204
|
+
Deletes the flag file indicating that the robot has finished execution.
|
201
205
|
"""
|
202
206
|
|
203
207
|
try:
|
@@ -210,20 +214,19 @@ class File:
|
|
210
214
|
|
211
215
|
if os.path.exists(full_path_with_name):
|
212
216
|
os.remove(full_path_with_name)
|
213
|
-
if
|
217
|
+
if verbose:
|
214
218
|
success_print("Flag file deleted.")
|
215
219
|
else:
|
216
220
|
alert_print("Flag file not found.")
|
217
221
|
|
218
222
|
except Exception as e:
|
219
|
-
|
220
|
-
time.sleep(1)
|
223
|
+
FileError(f"Error in function file_scheduling_delete: {str(e)}") from e
|
221
224
|
|
222
225
|
def count_files(
|
223
226
|
self,
|
224
227
|
dir_to_count: List[str] = ["."],
|
225
228
|
type_extension: str = "*",
|
226
|
-
|
229
|
+
verbose: bool = False,
|
227
230
|
) -> Dict[str, Union[bool, int]]:
|
228
231
|
"""
|
229
232
|
Function responsible for counting files within a folder, considers subfolders to do the count, searches by file type, being all files by default. \n
|
@@ -241,18 +244,18 @@ class File:
|
|
241
244
|
|
242
245
|
Description: pt-br
|
243
246
|
----------
|
244
|
-
|
247
|
+
Function responsible for counting files within a folder, considers subfolders to do the count, searches by file type, being all files by default. \n
|
245
248
|
|
246
|
-
|
249
|
+
Parameters:
|
247
250
|
----------
|
248
|
-
``dir_to_count: list`` -
|
249
|
-
``type_extension: str`` -
|
251
|
+
``dir_to_count: list`` - should be a list, accepts more than one path to count files.
|
252
|
+
``type_extension: str`` - should be a string with the format/extension of the type of file you want to be searched for counting, if empty by default will be used ``*`` which will count all files.
|
250
253
|
|
251
|
-
|
254
|
+
Return:
|
252
255
|
----------
|
253
256
|
>>> type:dict
|
254
|
-
* 'success': bool -
|
255
|
-
* 'qt': int -
|
257
|
+
* 'success': bool - represents if the action was performed successfully
|
258
|
+
* 'qt': int - number that represents the quantity of files that were counted
|
256
259
|
"""
|
257
260
|
|
258
261
|
# Local Variables
|
@@ -267,11 +270,11 @@ class File:
|
|
267
270
|
result["qt"] += 1
|
268
271
|
result["success"] = True
|
269
272
|
|
270
|
-
if
|
273
|
+
if verbose:
|
271
274
|
success_print(f'Function: {self.count_files.__name__} counted {result["qt"]} files.')
|
272
275
|
|
273
276
|
except Exception as e:
|
274
277
|
result["success"] = False
|
275
|
-
|
278
|
+
FileError(f"Error when trying to count files! Error: {str(e)}")
|
276
279
|
|
277
280
|
return result
|
rpa_suite/core/iris.py
CHANGED
@@ -1,108 +1,131 @@
|
|
1
1
|
# rpa_suite/core/iris.py
|
2
2
|
|
3
3
|
"""
|
4
|
-
Iris (OCR-
|
4
|
+
Iris (OCR-AI) module for document conversion using DocLing.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
This module provides a simplified interface for converting documents
|
7
|
+
in various formats, optimized for use in RPA automation.
|
8
8
|
"""
|
9
9
|
|
10
|
-
# imports
|
10
|
+
# external imports
|
11
11
|
try:
|
12
|
-
from docling.document_converter import DocumentConverter
|
12
|
+
from docling.document_converter import DocumentConverter as IrisEngine
|
13
13
|
except ImportError as e:
|
14
|
-
raise ImportError("Iris - Error:
|
14
|
+
raise ImportError("Iris - Error: Could not import 'docling.document_converter'. Make sure the 'docling' library is installed.") from e
|
15
15
|
|
16
|
-
#
|
16
|
+
# third party imports
|
17
17
|
from enum import Enum
|
18
|
-
from
|
19
|
-
from typing import Any, Dict, List, Optional, Union
|
18
|
+
from typing import Optional, Union
|
20
19
|
|
21
|
-
# imports
|
22
|
-
from rpa_suite.functions._printer import
|
20
|
+
# internal imports
|
21
|
+
from rpa_suite.functions._printer import success_print
|
23
22
|
|
24
23
|
class IrisError(Exception):
|
25
|
-
"""
|
24
|
+
"""Custom exception for Iris errors."""
|
26
25
|
def __init__(self, message):
|
27
|
-
|
26
|
+
# Remove "Iris Error:" from message if it already exists, as it will be added by default
|
27
|
+
clean_message = message.replace("Iris Error:", "").strip()
|
28
|
+
super().__init__(f'Iris Error: {clean_message}')
|
28
29
|
|
29
30
|
class ExportFormats(Enum):
|
30
|
-
"""
|
31
|
+
"""Supported export formats for document conversion."""
|
31
32
|
MARKDOWN = "markdown"
|
32
33
|
DICT = "dict"
|
33
34
|
DOCTAGS = "doctags"
|
34
35
|
HTML = "html"
|
35
36
|
TEXT = "text"
|
37
|
+
INDENTEDTEXT = "indented_text"
|
36
38
|
|
37
39
|
class Iris:
|
38
40
|
"""
|
39
|
-
Iris (OCR-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Markdown, HTML,
|
45
|
-
|
46
|
-
|
47
|
-
engine
|
48
|
-
last_result
|
49
|
-
|
50
|
-
|
41
|
+
Iris (OCR-AI)
|
42
|
+
Document converter with support for multiple extensions.
|
43
|
+
|
44
|
+
This class provides a simplified interface to convert documents
|
45
|
+
in various formats (PDF, images, text) to structured formats like
|
46
|
+
Markdown, HTML, plain text, among others.
|
47
|
+
|
48
|
+
Attributes:
|
49
|
+
``engine:`` IrisEngine instance.
|
50
|
+
``last_result:`` Last processed conversion result.
|
51
|
+
``list_results:`` List of results generated by batch processing with: ``read_documents``
|
52
|
+
|
53
|
+
On Error:
|
54
|
+
Raise ``IrisError``: If the document conversion fails.
|
55
|
+
|
56
|
+
Example:
|
57
|
+
>>> from rpa_suite.core import ExportFormats
|
51
58
|
>>> iris = Iris()
|
52
59
|
>>> content = iris.read_document("document.pdf", ExportFormats.MARKDOWN)
|
53
60
|
>>> print(content)
|
54
61
|
"""
|
55
62
|
|
56
|
-
engine: Optional[
|
63
|
+
engine: Optional[IrisEngine]
|
64
|
+
last_result = None
|
65
|
+
list_results = list | None
|
57
66
|
|
58
67
|
def __init__(self) -> None:
|
59
68
|
"""
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
69
|
+
Iris (OCR-AI)
|
70
|
+
Document converter with support for multiple extensions.
|
71
|
+
|
72
|
+
This class provides a simplified interface to convert documents
|
73
|
+
in various formats (PDF, images, text) to structured formats like
|
74
|
+
Markdown, HTML, plain text, among others.
|
75
|
+
|
76
|
+
Attributes:
|
77
|
+
``engine:`` IrisEngine instance.
|
78
|
+
``last_result:`` Last processed conversion result.
|
79
|
+
``list_results:`` List of results generated by batch processing with: ``read_documents``
|
80
|
+
|
81
|
+
On Error:
|
82
|
+
Raise ``IrisError``: If the document conversion fails.
|
83
|
+
|
84
|
+
Example:
|
85
|
+
>>> from rpa_suite.core import ExportFormats
|
86
|
+
>>> iris = Iris()
|
87
|
+
>>> content = iris.read_document("document.pdf", ExportFormats.MARKDOWN)
|
88
|
+
>>> print(content)
|
64
89
|
"""
|
65
90
|
try:
|
66
|
-
self.
|
67
|
-
self.engine = self.iris_converter
|
68
|
-
self.path_file = None
|
91
|
+
self.engine = IrisEngine()
|
69
92
|
self.result_converted = None
|
70
|
-
self.
|
93
|
+
self.last_result = None
|
94
|
+
self.list_results = []
|
95
|
+
|
71
96
|
except Exception as e:
|
72
|
-
|
73
|
-
raise IrisError(f"Falha ao inicializar o DocumentConverter: {e}")
|
97
|
+
raise IrisError(f"Failed to initialize DocumentConverter: {str(e)}.")
|
74
98
|
|
75
99
|
def __convert_document(self, path_file: str = None):
|
76
100
|
"""
|
77
|
-
|
101
|
+
Converts the document specified by the path.
|
78
102
|
|
79
|
-
|
80
|
-
IrisError
|
103
|
+
Raises:
|
104
|
+
``IrisError:`` If an error occurs during document conversion.
|
81
105
|
"""
|
82
106
|
try:
|
83
107
|
if not path_file:
|
84
|
-
raise IrisError("
|
85
|
-
self.result_converted = self.
|
108
|
+
raise IrisError("Specify the file path for conversion.")
|
109
|
+
self.result_converted = self.engine.convert(path_file)
|
86
110
|
except Exception as e:
|
87
|
-
|
88
|
-
raise IrisError(f"Falha ao converter o documento: {e}")
|
111
|
+
raise IrisError(f"Error trying to convert document! {str(e)}.")
|
89
112
|
|
90
113
|
def read_document(self, file_path: str = None, result_format=ExportFormats.MARKDOWN, verbose: bool = False) -> Optional[Union[str, dict]]:
|
91
114
|
"""
|
92
|
-
|
115
|
+
Reads and converts a document to the specified format.
|
93
116
|
|
94
117
|
Args:
|
95
|
-
file_path
|
96
|
-
result_format
|
97
|
-
verbose
|
118
|
+
``file_path:`` Path to the document file.
|
119
|
+
``result_format:`` Desired export format.
|
120
|
+
``verbose:`` If True, displays success messages.
|
98
121
|
|
99
|
-
|
100
|
-
|
122
|
+
Returns:
|
123
|
+
Document converted to the specified format, or None if it fails.
|
101
124
|
|
102
|
-
|
103
|
-
IrisError
|
125
|
+
Raises:
|
126
|
+
``IrisError:`` If an error occurs during validation, conversion or export.
|
104
127
|
|
105
|
-
|
128
|
+
Example:
|
106
129
|
>>> iris = Iris()
|
107
130
|
>>> content = iris.read_document("doc.pdf", ExportFormats.TEXT)
|
108
131
|
>>> print(content)
|
@@ -111,30 +134,83 @@ class Iris:
|
|
111
134
|
self.__convert_document(file_path)
|
112
135
|
|
113
136
|
if not self.result_converted or not hasattr(self.result_converted, 'document'):
|
114
|
-
raise IrisError("
|
137
|
+
raise IrisError("Failed to convert file or invalid object resulted.")
|
115
138
|
|
116
139
|
if result_format == ExportFormats.MARKDOWN:
|
117
|
-
self.
|
140
|
+
self.last_result = self.result_converted.document.export_to_markdown()
|
118
141
|
elif result_format == ExportFormats.DICT:
|
119
|
-
self.
|
142
|
+
self.last_result = self.result_converted.document.export_to_dict()
|
120
143
|
elif result_format == ExportFormats.DOCTAGS:
|
121
|
-
self.
|
144
|
+
self.last_result = self.result_converted.document.export_to_doctags()
|
122
145
|
elif result_format == ExportFormats.HTML:
|
123
|
-
self.
|
146
|
+
self.last_result = self.result_converted.document.export_to_html()
|
124
147
|
elif result_format == ExportFormats.TEXT:
|
125
|
-
self.
|
148
|
+
self.last_result = self.result_converted.document.export_to_text()
|
149
|
+
elif result_format == ExportFormats.INDENTEDTEXT:
|
150
|
+
self.last_result = self.result_converted.document._export_to_indented_text()
|
126
151
|
else:
|
127
|
-
|
128
|
-
raise IrisError(f"Formato não suportado: {result_format}.")
|
129
|
-
|
152
|
+
raise IrisError(f"Not supported format: {result_format}.")
|
130
153
|
if verbose:
|
131
|
-
success_print('
|
154
|
+
success_print('Iris: Successfully converted!')
|
132
155
|
|
133
|
-
return self.
|
134
|
-
|
135
|
-
except IrisError as ie:
|
136
|
-
error_print(str(ie))
|
137
|
-
return None
|
156
|
+
return self.last_result
|
138
157
|
except Exception as e:
|
139
|
-
|
140
|
-
|
158
|
+
raise IrisError(f"Error trying to read document: {str(e)}.")
|
159
|
+
|
160
|
+
def read_documents(self, list_file_path: list[str] = None, result_format=ExportFormats.MARKDOWN, verbose: bool = False) -> Optional[list]:
|
161
|
+
"""
|
162
|
+
Reads and converts multiple documents to the specified format.
|
163
|
+
|
164
|
+
Args:
|
165
|
+
``list_file_path:`` List of documents in path format.
|
166
|
+
``result_format:`` Desired export format.
|
167
|
+
``verbose:`` If True, displays success messages.
|
168
|
+
|
169
|
+
Returns:
|
170
|
+
``List`` of documents converted to the specified format, or None if it fails.
|
171
|
+
|
172
|
+
Raises:
|
173
|
+
``IrisError:`` If an error occurs during validation, conversion or export.
|
174
|
+
|
175
|
+
Example:
|
176
|
+
>>> iris = Iris()
|
177
|
+
>>> contents = iris.read_documents(["doc.pdf", "doc2.docx"], ExportFormats.TEXT)
|
178
|
+
>>> print(contents)
|
179
|
+
"""
|
180
|
+
self.list_results = []
|
181
|
+
|
182
|
+
for file_path in list_file_path:
|
183
|
+
try:
|
184
|
+
self.__convert_document(file_path)
|
185
|
+
|
186
|
+
if not self.result_converted or not hasattr(self.result_converted, 'document'):
|
187
|
+
raise IrisError("Failed to convert file or invalid object resulted.")
|
188
|
+
|
189
|
+
if result_format == ExportFormats.MARKDOWN:
|
190
|
+
self.last_result = self.result_converted.document.export_to_markdown()
|
191
|
+
self.list_results.append(self.last_result)
|
192
|
+
elif result_format == ExportFormats.DICT:
|
193
|
+
self.last_result = self.result_converted.document.export_to_dict()
|
194
|
+
self.list_results.append(self.last_result)
|
195
|
+
elif result_format == ExportFormats.DOCTAGS:
|
196
|
+
self.last_result = self.result_converted.document.export_to_doctags()
|
197
|
+
self.list_results.append(self.last_result)
|
198
|
+
elif result_format == ExportFormats.HTML:
|
199
|
+
self.last_result = self.result_converted.document.export_to_html()
|
200
|
+
self.list_results.append(self.last_result)
|
201
|
+
elif result_format == ExportFormats.TEXT:
|
202
|
+
self.last_result = self.result_converted.document.export_to_text()
|
203
|
+
self.list_results.append(self.last_result)
|
204
|
+
elif result_format == ExportFormats.INDENTEDTEXT:
|
205
|
+
self.last_result = self.result_converted.document._export_to_indented_text()
|
206
|
+
self.list_results.append(self.last_result)
|
207
|
+
else:
|
208
|
+
raise IrisError(f"Not supported format: {result_format}.")
|
209
|
+
if verbose:
|
210
|
+
success_print('Iris: Successfully converted!')
|
211
|
+
except IrisError as ie:
|
212
|
+
raise ie from ie
|
213
|
+
except Exception as e:
|
214
|
+
raise IrisError(f"Error trying to read documents: {str(e)}.")
|
215
|
+
|
216
|
+
return self.list_results
|