rpa-suite 1.6.0__tar.gz → 1.6.1__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 (33) hide show
  1. {rpa_suite-1.6.0/rpa_suite.egg-info → rpa_suite-1.6.1}/PKG-INFO +5 -7
  2. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/README.md +4 -6
  3. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/__init__.py +1 -1
  4. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/__init__.py +6 -3
  5. rpa_suite-1.6.1/rpa_suite/core/iris.py +140 -0
  6. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/functions/__init__.py +1 -1
  7. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/suite.py +3 -2
  8. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/utils/__init__.py +1 -1
  9. {rpa_suite-1.6.0 → rpa_suite-1.6.1/rpa_suite.egg-info}/PKG-INFO +5 -7
  10. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/setup.py +1 -1
  11. rpa_suite-1.6.0/rpa_suite/core/iris.py +0 -327
  12. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/LICENSE +0 -0
  13. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/pyproject.toml +0 -0
  14. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/asyncrun.py +0 -0
  15. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/browser.py +0 -0
  16. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/clock.py +0 -0
  17. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/date.py +0 -0
  18. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/dir.py +0 -0
  19. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/email.py +0 -0
  20. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/file.py +0 -0
  21. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/log.py +0 -0
  22. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/parallel.py +0 -0
  23. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/print.py +0 -0
  24. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/regex.py +0 -0
  25. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/core/validate.py +0 -0
  26. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/functions/__create_ss_dir.py +0 -0
  27. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/functions/_printer.py +0 -0
  28. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite/utils/system.py +0 -0
  29. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite.egg-info/SOURCES.txt +0 -0
  30. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite.egg-info/dependency_links.txt +0 -0
  31. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite.egg-info/requires.txt +0 -0
  32. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/rpa_suite.egg-info/top_level.txt +0 -0
  33. {rpa_suite-1.6.0 → rpa_suite-1.6.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rpa_suite
3
- Version: 1.6.0
3
+ Version: 1.6.1
4
4
  Summary: Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.
5
5
  Author: Camilo Costa de Carvalho
6
6
  Author-email: camilo.carvalho@vettracode.com
@@ -186,12 +186,12 @@ No setup do nosso projeto já estão inclusas as dependências, só será necess
186
186
  - pillow
187
187
  - pyautogui
188
188
  - typing
189
- - setuptools
190
189
 
191
- opcionalmente para automação de navegador:
190
+ opcionalmente para usar todas funcionalidades:
192
191
 
193
192
  - selenium
194
193
  - webdriver_manager
194
+ - docling
195
195
 
196
196
  <br>
197
197
  <hr>
@@ -285,14 +285,12 @@ O módulo principal do rpa-suite é dividido em categorias. Cada categoria cont
285
285
  **Iris (OCR-IA)**
286
286
 
287
287
  - **read_document** - Reads and converts a document to the specified format.
288
- - **read_multiple_documents** - Reads and converts multiple documents.
289
- - **get_supported_extensions** - Returns the list of supported file extensions
290
- - **is_file_supported** - Checks if a file is supported by the class.
291
288
 
289
+ <br>
292
290
 
293
291
  ## Release Notes
294
292
 
295
- ### Versão: **Beta 1.6.0**
293
+ ### Versão: **Beta 1.6.1**
296
294
 
297
295
  - **Data de Lançamento:** *20/02/2024*
298
296
  - **Última Atualização:** 08/06/2025
@@ -141,12 +141,12 @@ No setup do nosso projeto já estão inclusas as dependências, só será necess
141
141
  - pillow
142
142
  - pyautogui
143
143
  - typing
144
- - setuptools
145
144
 
146
- opcionalmente para automação de navegador:
145
+ opcionalmente para usar todas funcionalidades:
147
146
 
148
147
  - selenium
149
148
  - webdriver_manager
149
+ - docling
150
150
 
151
151
  <br>
152
152
  <hr>
@@ -240,14 +240,12 @@ O módulo principal do rpa-suite é dividido em categorias. Cada categoria cont
240
240
  **Iris (OCR-IA)**
241
241
 
242
242
  - **read_document** - Reads and converts a document to the specified format.
243
- - **read_multiple_documents** - Reads and converts multiple documents.
244
- - **get_supported_extensions** - Returns the list of supported file extensions
245
- - **is_file_supported** - Checks if a file is supported by the class.
246
243
 
244
+ <br>
247
245
 
248
246
  ## Release Notes
249
247
 
250
- ### Versão: **Beta 1.6.0**
248
+ ### Versão: **Beta 1.6.1**
251
249
 
252
250
  - **Data de Lançamento:** *20/02/2024*
253
251
  - **Última Atualização:** 08/06/2025
@@ -66,7 +66,7 @@ Módulos disponíveis:
66
66
  ``Iris``: Objeto Iris Automação de funções para converter documentos com OCR + IA baseado em ``docling``
67
67
  """
68
68
 
69
- __version__ = "1.5.9"
69
+ __version__ = "1.6.1"
70
70
 
71
71
  # allows importing the rpa_suite module without the package name
72
72
  from .suite import rpa
@@ -36,13 +36,16 @@ from .parallel import ParallelRunner
36
36
  from .asyncrun import AsyncRunner
37
37
 
38
38
 
39
- # On this case, we are importing the Browser class only if the selenium and webdriver_manager modules are installed.
40
- # This is useful to avoid unnecessary imports and dependencies if the user does not need the Browser functionality.
39
+ # On this case, we are importing the (Browser|Iris) class only if the (selenium and webdriver_manager| docling) modules are installed.
40
+ # This is useful to avoid unnecessary imports and dependencies if the user does not need the (Browser|Iris) functionality.
41
41
  import importlib.util
42
42
 
43
43
  # from .browser import Browser
44
44
  if importlib.util.find_spec("selenium") and importlib.util.find_spec("webdriver_manager"):
45
45
  from .browser import Browser
46
46
 
47
+ # from .iris import Iris
48
+ if importlib.util.find_spec("docling"):
49
+ from .iris import Iris
47
50
 
48
- __version__ = "1.5.5"
51
+ __version__ = "1.6.1"
@@ -0,0 +1,140 @@
1
+ # rpa_suite/core/iris.py
2
+
3
+ """
4
+ Iris (OCR-IA) módulo para conversão de documentos usando DocLing.
5
+
6
+ Este módulo fornece uma interface simplificada para converter documentos
7
+ em vários formatos, otimizado para uso em automação RPA.
8
+ """
9
+
10
+ # imports externos
11
+ try:
12
+ from docling.document_converter import DocumentConverter
13
+ except ImportError as e:
14
+ raise ImportError("Iris - Error: Não foi possível importar 'docling.document_converter'. Certifique-se de que a biblioteca 'docling' está instalada.") from e
15
+
16
+ # imports de terceiros
17
+ from enum import Enum
18
+ from pathlib import Path
19
+ from typing import Any, Dict, List, Optional, Union
20
+
21
+ # imports internos
22
+ from rpa_suite.functions._printer import alert_print, error_print, success_print
23
+
24
+ class IrisError(Exception):
25
+ """Exceção personalizada para erros do Iris."""
26
+ def __init__(self, message):
27
+ super().__init__(f'Iris - Error: {message}')
28
+
29
+ class ExportFormats(Enum):
30
+ """Formatos de exportação suportados para conversão de documentos."""
31
+ MARKDOWN = "markdown"
32
+ DICT = "dict"
33
+ DOCTAGS = "doctags"
34
+ HTML = "html"
35
+ TEXT = "text"
36
+
37
+ class Iris:
38
+ """
39
+ Iris (OCR-IA)
40
+ Conversor de documentos usando a biblioteca DocLing.
41
+
42
+ Esta classe fornece uma interface simplificada para converter documentos
43
+ em vários formatos (PDF, imagens, texto) para formatos estruturados como
44
+ Markdown, HTML, texto simples, entre outros.
45
+
46
+ Atributos:
47
+ engine: Instância do DocumentConverter do DocLing.
48
+ last_result: Último resultado de conversão processado.
49
+
50
+ Exemplo:
51
+ >>> iris = Iris()
52
+ >>> content = iris.read_document("document.pdf", ExportFormats.MARKDOWN)
53
+ >>> print(content)
54
+ """
55
+
56
+ engine: Optional[DocumentConverter]
57
+
58
+ def __init__(self) -> None:
59
+ """
60
+ Inicializa a classe Iris com o conversor de documentos.
61
+
62
+ Levanta:
63
+ IrisError: Se a biblioteca DocLing não estiver instalada.
64
+ """
65
+ try:
66
+ self.iris_converter = DocumentConverter()
67
+ self.engine = self.iris_converter
68
+ self.path_file = None
69
+ self.result_converted = None
70
+ self.result_formatted = None
71
+ except Exception as e:
72
+ error_print("Iris - Error: Falha ao inicializar o DocumentConverter.")
73
+ raise IrisError(f"Falha ao inicializar o DocumentConverter: {e}")
74
+
75
+ def __convert_document(self, path_file: str = None):
76
+ """
77
+ Converte o documento informado pelo caminho.
78
+
79
+ Levanta:
80
+ IrisError: Se ocorrer erro na conversão do documento.
81
+ """
82
+ try:
83
+ if not path_file:
84
+ raise IrisError("Caminho do arquivo não informado para conversão.")
85
+ self.result_converted = self.iris_converter.convert(path_file)
86
+ except Exception as e:
87
+ error_print(f"Iris - Error: Falha ao converter o documento: {e}")
88
+ raise IrisError(f"Falha ao converter o documento: {e}")
89
+
90
+ def read_document(self, file_path: str = None, result_format=ExportFormats.MARKDOWN, verbose: bool = False) -> Optional[Union[str, dict]]:
91
+ """
92
+ Lê e converte um documento para o formato especificado.
93
+
94
+ Args:
95
+ file_path: Caminho para o arquivo do documento.
96
+ result_format: Formato de exportação desejado.
97
+ verbose: Se True, exibe mensagens de sucesso.
98
+
99
+ Retorna:
100
+ Documento convertido para o formato especificado, ou None se falhar.
101
+
102
+ Levanta:
103
+ IrisError: Se ocorrer erro durante validação, conversão ou exportação.
104
+
105
+ Exemplo:
106
+ >>> iris = Iris()
107
+ >>> content = iris.read_document("doc.pdf", ExportFormats.TEXT)
108
+ >>> print(content)
109
+ """
110
+ try:
111
+ self.__convert_document(file_path)
112
+
113
+ if not self.result_converted or not hasattr(self.result_converted, 'document'):
114
+ raise IrisError("Conversão falhou ou objeto retornado inválido.")
115
+
116
+ if result_format == ExportFormats.MARKDOWN:
117
+ self.result_formatted = self.result_converted.document.export_to_markdown()
118
+ elif result_format == ExportFormats.DICT:
119
+ self.result_formatted = self.result_converted.document.export_to_dict()
120
+ elif result_format == ExportFormats.DOCTAGS:
121
+ self.result_formatted = self.result_converted.document.export_to_doctags()
122
+ elif result_format == ExportFormats.HTML:
123
+ self.result_formatted = self.result_converted.document.export_to_html()
124
+ elif result_format == ExportFormats.TEXT:
125
+ self.result_formatted = self.result_converted.document.export_to_text()
126
+ else:
127
+ alert_print(f'Iris - Error: Formato não suportado: {result_format}.')
128
+ raise IrisError(f"Formato não suportado: {result_format}.")
129
+
130
+ if verbose:
131
+ success_print('Irir - Convertido com sucesso!')
132
+
133
+ return self.result_formatted
134
+
135
+ except IrisError as ie:
136
+ error_print(str(ie))
137
+ return None
138
+ except Exception as e:
139
+ error_print(f"Iris - Error: Erro inesperado ao ler o documento: {e}")
140
+ raise IrisError(f"Erro inesperado ao ler o documento: {e}")
@@ -1,3 +1,3 @@
1
1
  # rpa_suite/functions/__init__.py
2
2
 
3
- __version__ = "1.5.5"
3
+ __version__ = "1.6.1"
@@ -155,7 +155,8 @@ class Suite:
155
155
  Parallel: ParallelRunner = ParallelRunner
156
156
  Asyn: AsyncRunner = AsyncRunner
157
157
 
158
- # On this case, we are importing the (Browser | Iris) class only if the selenium and webdriver_manager modules are installed.
158
+
159
+ # On this case, we are importing the (Browser | Iris) class only if the (selenium and webdriver_manager| docling) modules are installed.
159
160
  # This is useful to avoid unnecessary imports and dependencies if the user does not need the (Browser | Iris) functionality.
160
161
  import importlib.util
161
162
 
@@ -334,7 +335,7 @@ class Suite:
334
335
  "setuptools",
335
336
  "wheel",
336
337
  "pyperclip",
337
- "pywin32"
338
+ "pywin32",
338
339
  "colorama",
339
340
  "colorlog",
340
341
  "email_validator",
@@ -12,4 +12,4 @@ O módulo de utilitários da rpa-suite fornece uma coleção de funções e clas
12
12
  from .system import Tools
13
13
 
14
14
 
15
- __version__ = "1.5.5"
15
+ __version__ = "1.6.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rpa_suite
3
- Version: 1.6.0
3
+ Version: 1.6.1
4
4
  Summary: Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.
5
5
  Author: Camilo Costa de Carvalho
6
6
  Author-email: camilo.carvalho@vettracode.com
@@ -186,12 +186,12 @@ No setup do nosso projeto já estão inclusas as dependências, só será necess
186
186
  - pillow
187
187
  - pyautogui
188
188
  - typing
189
- - setuptools
190
189
 
191
- opcionalmente para automação de navegador:
190
+ opcionalmente para usar todas funcionalidades:
192
191
 
193
192
  - selenium
194
193
  - webdriver_manager
194
+ - docling
195
195
 
196
196
  <br>
197
197
  <hr>
@@ -285,14 +285,12 @@ O módulo principal do rpa-suite é dividido em categorias. Cada categoria cont
285
285
  **Iris (OCR-IA)**
286
286
 
287
287
  - **read_document** - Reads and converts a document to the specified format.
288
- - **read_multiple_documents** - Reads and converts multiple documents.
289
- - **get_supported_extensions** - Returns the list of supported file extensions
290
- - **is_file_supported** - Checks if a file is supported by the class.
291
288
 
289
+ <br>
292
290
 
293
291
  ## Release Notes
294
292
 
295
- ### Versão: **Beta 1.6.0**
293
+ ### Versão: **Beta 1.6.1**
296
294
 
297
295
  - **Data de Lançamento:** *20/02/2024*
298
296
  - **Última Atualização:** 08/06/2025
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="rpa_suite",
5
- version="1.6.0",
5
+ version="1.6.1",
6
6
  packages=find_packages(),
7
7
  description="Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.",
8
8
  long_description_content_type="text/markdown",
@@ -1,327 +0,0 @@
1
- # rpa_suite/core/iris.py
2
- """
3
- Iris (OCR-IA) module for document conversion using DocLing.
4
-
5
- This module provides a simplified interface for converting documents
6
- into various formats, optimized for RPA automation use.
7
- """
8
-
9
- from enum import Enum
10
- from pathlib import Path
11
- from typing import Any, Dict, List, Optional, Union
12
-
13
- # imports internal
14
- from rpa_suite.functions._printer import alert_print, error_print, success_print
15
-
16
-
17
- class ExportFormat(Enum):
18
- """Supported export formats for document conversion."""
19
-
20
- MARKDOWN = "markdown"
21
- DICT = "dict"
22
- DOCTAGS = "doctags"
23
- HTML = "html"
24
- TEXT = "text"
25
-
26
-
27
- class IrisError(Exception):
28
- """Custom exception for Iris class errors."""
29
-
30
- pass
31
-
32
-
33
- class Iris:
34
- """
35
- Iris (OCR-IA)
36
- Document converter using the DocLing library.
37
-
38
- This class provides a simplified interface for converting documents
39
- in various formats (PDF, images, text) to structured formats such as
40
- Markdown, HTML, plain text, among others.
41
-
42
- Attributes:
43
- engine: Instance of DocLing's DocumentConverter.
44
- last_result: Last processed conversion result.
45
-
46
- Example:
47
- >>> iris = Iris()
48
- >>> content = iris.read_document("document.pdf", ExportFormat.MARKDOWN)
49
- >>> print(content)
50
- """
51
-
52
- # Supported file extensions
53
- SUPPORTED_EXTENSIONS = {
54
- '.pdf', '.txt', '.docx', '.doc', '.png', '.jpg', '.jpeg',
55
- '.tiff', '.bmp', '.webp', '.pptx', '.xlsx'
56
- }
57
-
58
- def __init__(self, display_message: bool = False) -> None:
59
- """
60
- Initializes the Iris class with the document converter.
61
-
62
- Raises:
63
- IrisError: If the DocLing library is not installed.
64
- """
65
- self._engine: Optional[Any] = None
66
- self._last_result: Optional[Any] = None
67
- self.display_message: bool = display_message
68
- self._initialize_engine()
69
-
70
- def _initialize_engine(self) -> None:
71
- """
72
- Initializes the DocumentConverter engine.
73
-
74
- Raises:
75
- IrisError: If the DocLing library is not available.
76
- """
77
- try:
78
- from docling.document_converter import DocumentConverter
79
- self._engine = DocumentConverter()
80
- if self.display_message: success_print("Iris engine initialized successfully")
81
- except ImportError as e:
82
- error_msg = (
83
- "The 'docling' library is not installed. "
84
- "Run: python -m pip install docling"
85
- )
86
- error_print(f"Iris - {error_msg}")
87
- error_print(f"Error importing DocLing: {e}")
88
- raise IrisError(error_msg) from e
89
-
90
- @property
91
- def engine(self) -> Any:
92
- """Returns the DocumentConverter engine instance."""
93
- return self._engine
94
-
95
- @property
96
- def last_result(self) -> Optional[Any]:
97
- """Returns the last processed conversion result."""
98
- return self._last_result
99
-
100
- def _validate_file_path(self, file_path: Union[str, Path]) -> Path:
101
- """
102
- Validates the file path and returns a Path object.
103
-
104
- Args:
105
- file_path: Path to the file.
106
-
107
- Returns:
108
- Path: Validated Path object.
109
-
110
- Raises:
111
- IrisError: If the file does not exist or is not supported.
112
- """
113
- path_obj = Path(file_path)
114
-
115
- if not path_obj.exists():
116
- raise IrisError(f"File not found: {file_path}")
117
-
118
- if not path_obj.is_file():
119
- raise IrisError(f"Path does not point to a file: {file_path}")
120
-
121
- if path_obj.suffix.lower() not in self.SUPPORTED_EXTENSIONS:
122
- supported = ", ".join(sorted(self.SUPPORTED_EXTENSIONS))
123
- raise IrisError(
124
- f"Extension '{path_obj.suffix}' is not supported. "
125
- f"Supported extensions: {supported}"
126
- )
127
-
128
- return path_obj
129
-
130
- def _convert_document(self, file_path: Path) -> Any:
131
- """
132
- Converts the document using DocumentConverter.
133
-
134
- Args:
135
- file_path: Path to the file.
136
-
137
- Returns:
138
- Result of the DocLing conversion.
139
-
140
- Raises:
141
- IrisError: If the conversion fails.
142
- """
143
- try:
144
- if self.display_message: success_print(f"Starting conversion of file: {file_path}")
145
- result = self._engine.convert(str(file_path))
146
- self._last_result = result
147
- if self.display_message: success_print("Conversion completed successfully")
148
- return result
149
- except Exception as e:
150
- error_msg = f"Error converting document '{file_path}': {e}"
151
- error_print(f"Iris - {error_msg}")
152
- error_print(error_msg)
153
- raise IrisError(error_msg) from e
154
-
155
- def _export_to_format(self, document: Any, export_format: ExportFormat) -> Any:
156
- """
157
- Exports the document to the specified format.
158
-
159
- Args:
160
- document: Document converted by DocLing.
161
- export_format: Desired export format.
162
-
163
- Returns:
164
- Document in the specified format.
165
-
166
- Raises:
167
- IrisError: If the export fails.
168
- """
169
- export_methods = {
170
- ExportFormat.MARKDOWN: document.export_to_markdown,
171
- ExportFormat.DICT: document.export_to_dict,
172
- ExportFormat.DOCTAGS: document.export_to_doctags,
173
- ExportFormat.HTML: document.export_to_html,
174
- ExportFormat.TEXT: document.export_to_text,
175
- }
176
-
177
- try:
178
- export_method = export_methods[export_format]
179
- return export_method()
180
- except KeyError:
181
- available_formats = ", ".join([fmt.value for fmt in ExportFormat])
182
- raise IrisError(
183
- f"Format '{export_format.value}' is not supported. "
184
- f"Available formats: {available_formats}"
185
- )
186
- except Exception as e:
187
- error_msg = f"Error exporting to format '{export_format.value}': {e}"
188
- error_print(error_msg)
189
- raise IrisError(error_msg) from e
190
-
191
- def read_document(
192
- self,
193
- file_path: Union[str, Path],
194
- export_format: ExportFormat = ExportFormat.MARKDOWN,
195
- verbose: bool = False,
196
- ) -> Optional[Any]:
197
- """
198
- Reads and converts a document to the specified format.
199
-
200
- Args:
201
- file_path: Path to the document file.
202
- export_format: Desired export format.
203
- verbose: If True, displays success messages.
204
-
205
- Returns:
206
- Document converted to the specified format, or None if it fails.
207
-
208
- Raises:
209
- IrisError: If an error occurs during validation, conversion, or export.
210
-
211
- Example:
212
- >>> iris = Iris()
213
- >>> content = iris.read_document("doc.pdf", ExportFormat.TEXT)
214
- >>> print(content)
215
- """
216
- try:
217
- # File validation
218
- validated_path = self._validate_file_path(file_path)
219
-
220
- # Document conversion
221
- conversion_result = self._convert_document(validated_path)
222
-
223
- # Conversion result check
224
- if not conversion_result or not hasattr(conversion_result, 'document'):
225
- raise IrisError("Invalid conversion result or document not found")
226
-
227
- # Export to desired format
228
- formatted_result = self._export_to_format(
229
- conversion_result.document,
230
- export_format
231
- )
232
-
233
- if verbose:
234
- success_print("Iris - Conversion completed successfully")
235
-
236
- success_print(
237
- f"Document '{validated_path.name}' converted to '{export_format.value}'"
238
- )
239
-
240
- return formatted_result
241
-
242
- except IrisError:
243
- # Re-raise exceptions from the class itself
244
- raise
245
- except Exception as e:
246
- error_msg = f"Unexpected error while processing document: {e}"
247
- error_print(f"Iris - {error_msg}")
248
- error_print(error_msg)
249
- raise IrisError(error_msg) from e
250
-
251
- def read_multiple_documents(
252
- self,
253
- file_paths: List[Union[str, Path]],
254
- export_format: ExportFormat = ExportFormat.MARKDOWN,
255
- verbose: bool = False,
256
- ) -> Dict[str, Optional[Any]]:
257
- """
258
- Reads and converts multiple documents.
259
-
260
- Args:
261
- file_paths: List of file paths.
262
- export_format: Desired export format.
263
- verbose: If True, displays detailed messages.
264
-
265
- Returns:
266
- Dictionary with the file name as key and converted content as value.
267
-
268
- Example:
269
- >>> iris = Iris()
270
- >>> files = ["doc1.pdf", "doc2.txt"]
271
- >>> results = iris.read_multiple_documents(files, ExportFormat.TEXT)
272
- >>> for filename, content in results.items():
273
- ... print(f"{filename}: {len(content) if content else 0} characters")
274
- """
275
- results = {}
276
- successful_conversions = 0
277
-
278
- for file_path in file_paths:
279
- try:
280
- content = self.read_document(file_path, export_format, verbose=False)
281
- filename = Path(file_path).name
282
- results[filename] = content
283
- successful_conversions += 1
284
-
285
- if verbose:
286
- if self.display_message: success_print(f"Iris - '{filename}' converted successfully")
287
-
288
- except IrisError as e:
289
- filename = Path(file_path).name
290
- results[filename] = None
291
- if verbose:
292
- error_print(f"Iris - Error converting '{filename}': {e}")
293
- alert_print(f"Failed to convert '{filename}': {e}")
294
-
295
- if verbose:
296
- total_files = len(file_paths)
297
- if self.display_message: success_print(
298
- f"Iris - Processing completed: {successful_conversions}/{total_files} "
299
- f"files converted successfully"
300
- )
301
-
302
- return results
303
-
304
- def get_supported_extensions(self) -> List[str]:
305
- """
306
- Returns the list of supported file extensions.
307
-
308
- Returns:
309
- Sorted list of supported extensions.
310
- """
311
- return sorted(list(self.SUPPORTED_EXTENSIONS))
312
-
313
- def is_file_supported(self, file_path: Union[str, Path]) -> bool:
314
- """
315
- Checks if a file is supported by the class.
316
-
317
- Args:
318
- file_path: Path to the file.
319
-
320
- Returns:
321
- True if the file is supported, False otherwise.
322
- """
323
- try:
324
- path_obj = Path(file_path)
325
- return path_obj.suffix.lower() in self.SUPPORTED_EXTENSIONS
326
- except Exception:
327
- return False
File without changes
File without changes
File without changes