convert-stream 2.3.1__tar.gz → 2.3.3__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 (40) hide show
  1. {convert_stream-2.3.1 → convert_stream-2.3.3}/PKG-INFO +1 -1
  2. convert_stream-2.3.3/convert_stream/__init__.py +73 -0
  3. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/doc_stream.py +25 -40
  4. convert_stream-2.3.3/convert_stream/image/__init__.py +7 -0
  5. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/image/img_object.py +55 -40
  6. convert_stream-2.3.3/convert_stream/mod_types/__init__.py +42 -0
  7. {convert_stream-2.3.1/convert_stream/enum_libs → convert_stream-2.3.3/convert_stream/mod_types}/enums.py +13 -9
  8. {convert_stream-2.3.1/convert_stream/enum_libs → convert_stream-2.3.3/convert_stream/mod_types}/modules.py +3 -4
  9. convert_stream-2.3.3/convert_stream/mod_types/table_types.py +408 -0
  10. convert_stream-2.3.3/convert_stream/pdf/__init__.py +14 -0
  11. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/pdf/image_to_pdf.py +17 -17
  12. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/pdf/pdf_document.py +122 -85
  13. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/pdf/pdf_page.py +27 -116
  14. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/pdf/pdf_to_image.py +6 -6
  15. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/sheets/load.py +2 -2
  16. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/sheets/parse.py +1 -1
  17. convert_stream-2.3.3/convert_stream/table_files.py +138 -0
  18. convert_stream-2.3.3/convert_stream/text/__init__.py +11 -0
  19. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/text/date.py +1 -1
  20. convert_stream-2.3.3/convert_stream/text/find_text.py +50 -0
  21. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream.egg-info/PKG-INFO +1 -1
  22. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream.egg-info/SOURCES.txt +5 -4
  23. {convert_stream-2.3.1 → convert_stream-2.3.3}/pyproject.toml +2 -2
  24. convert_stream-2.3.1/convert_stream/__init__.py +0 -100
  25. convert_stream-2.3.1/convert_stream/enum_libs/__init__.py +0 -0
  26. convert_stream-2.3.1/convert_stream/image/__init__.py +0 -7
  27. convert_stream-2.3.1/convert_stream/pdf/__init__.py +0 -15
  28. convert_stream-2.3.1/convert_stream/table_files.py +0 -338
  29. convert_stream-2.3.1/convert_stream/text/__init__.py +0 -7
  30. convert_stream-2.3.1/convert_stream/text/string.py +0 -352
  31. {convert_stream-2.3.1 → convert_stream-2.3.3}/README.md +0 -0
  32. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/__main__.py +0 -0
  33. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/_version.py +0 -0
  34. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/sheets/__init__.py +0 -0
  35. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/sheets/save.py +0 -0
  36. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream/text/terminal.py +0 -0
  37. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream.egg-info/dependency_links.txt +0 -0
  38. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream.egg-info/requires.txt +0 -0
  39. {convert_stream-2.3.1 → convert_stream-2.3.3}/convert_stream.egg-info/top_level.txt +0 -0
  40. {convert_stream-2.3.1 → convert_stream-2.3.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 2.3.1
3
+ Version: 2.3.3
4
4
  Summary: Manipulação de documentos PDF e Imagens. Converter, Ler, rotacionar exportar etc.
5
5
  Author: Bruno Chaves
6
6
  Requires-Python: >=3.11
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+ from io import BytesIO
4
+ from typing import Union
5
+ from soup_files import File
6
+
7
+ from ._version import (
8
+ __module_name__, __author__, __license__, __modify_date__, __version__
9
+ )
10
+ from .image import ImageObject, CollectionImages
11
+ from .pdf import DocumentPdf, PageDocumentPdf, CollectionPagePdf
12
+ from .doc_stream import PdfStream
13
+
14
+
15
+ def __create_stream() -> PdfStream:
16
+ st = PdfStream()
17
+ st.clear()
18
+ return st
19
+
20
+
21
+ def read_pdf(file: Union[str, File, bytes, BytesIO]) -> PdfStream:
22
+ _pdf_stream = __create_stream()
23
+
24
+ if isinstance(file, File):
25
+ _pdf_stream.add_file_pdf(file)
26
+ elif isinstance(file, str):
27
+ _pdf_stream.add_file_pdf(File(file))
28
+ elif isinstance(file, bytes):
29
+ _pdf_stream.add_document(DocumentPdf(BytesIO(file)))
30
+ elif isinstance(file, BytesIO):
31
+ _pdf_stream.add_document(DocumentPdf(file))
32
+ else:
33
+ raise ValueError()
34
+ return _pdf_stream
35
+
36
+
37
+ def read_files_pdf(files: Union[list[str], list[File]]) -> PdfStream:
38
+ _pdf_stream = __create_stream()
39
+ if len(files) == 0:
40
+ return _pdf_stream
41
+
42
+ if isinstance(files[0], str):
43
+ for f in files:
44
+ _pdf_stream.add_file_pdf(File(f))
45
+ elif isinstance(files[0], File):
46
+ _pdf_stream.add_files_pdf(files)
47
+ else:
48
+ raise ValueError()
49
+ return _pdf_stream
50
+
51
+
52
+ def read_image(img: Union[str, File, bytes, BytesIO]) -> PdfStream:
53
+ _pdf_stream = __create_stream()
54
+ if isinstance(img, str):
55
+ _pdf_stream.add_file_image(File(img))
56
+ elif isinstance(img, File):
57
+ _pdf_stream.add_image(ImageObject.create_from_file(img))
58
+ elif isinstance(img, bytes):
59
+ _pdf_stream.add_image(ImageObject.create_from_bytes(img))
60
+ elif isinstance(img, BytesIO):
61
+ img.seek(0)
62
+ _pdf_stream.add_image(ImageObject.create_from_bytes(img.getvalue()))
63
+ else:
64
+ raise ValueError()
65
+ return _pdf_stream
66
+
67
+
68
+ __all__ = [
69
+ '__modify_date__', '__author__', '__license__', '__module_name__', '__version__',
70
+ 'PdfStream', 'DocumentPdf', 'PageDocumentPdf', 'CollectionPagePdf', 'CollectionImages',
71
+ 'read_pdf', 'read_files_pdf', 'read_image',
72
+ ]
73
+
@@ -4,38 +4,26 @@
4
4
  Módulo para trabalhar com pdfs e imagens
5
5
  """
6
6
  from __future__ import annotations
7
- from convert_stream.enum_libs.modules import (
7
+ from convert_stream.mod_types.modules import (
8
8
  DEFAULT_LIB_PDF, DEFAULT_LIB_IMAGE, DEFAULT_LIB_PDF_TO_IMG, DEFAULT_LIB_IMAGE_TO_PDF,
9
9
  )
10
- from convert_stream.enum_libs.enums import LibPDF, LibImage, LibImageToPdf, LibPdfToImage
10
+ from convert_stream.mod_types.enums import LibPDF, LibImage, LibPdfToImage
11
11
  from convert_stream.pdf.pdf_page import PageDocumentPdf
12
12
  from convert_stream.image.img_object import ImageObject, CollectionImages
13
13
  from convert_stream.pdf.pdf_document import DocumentPdf, CollectionPagePdf
14
14
  from convert_stream.pdf.image_to_pdf import LibImageToPdf, ConvertImageToPdf
15
15
  from convert_stream.pdf.pdf_to_image import ConvertPdfToImages
16
- from soup_files import File, Directory, ProgressBarAdapter, ABCProgressBar
17
-
18
-
19
- class VoidProgressBar(ABCProgressBar):
20
-
21
- def __init__(self):
22
- super().__init__()
23
-
24
- def set_percent(self, percent: float):
25
- pass
26
-
27
- def set_text(self, text: str):
28
- pass
16
+ from soup_files import File, Directory, ProgressBarAdapter
29
17
 
30
18
 
31
19
  class ImageStream(CollectionImages):
32
20
 
33
- def __init__(self, images: list[ImageObject] = []) -> None:
21
+ def __init__(self, images: list[ImageObject]) -> None:
34
22
  super().__init__(images)
35
23
 
36
24
  def add_image_bytes(self, bt: bytes) -> None:
37
25
  im = ImageObject.create_from_bytes(bt)
38
- self.images.append(im)
26
+ self.append(im)
39
27
 
40
28
 
41
29
  class PdfStream(object):
@@ -49,8 +37,8 @@ class PdfStream(object):
49
37
  lib_pdf_to_img: LibPdfToImage = DEFAULT_LIB_PDF_TO_IMG,
50
38
  ) -> None:
51
39
  self.progress: ProgressBarAdapter = pbar
52
- self.collection_pages: CollectionPagePdf = CollectionPagePdf()
53
- self.collection_images: CollectionImages = CollectionImages()
40
+ self.collection_pages: CollectionPagePdf = CollectionPagePdf([])
41
+ self.collection_images: CollectionImages = CollectionImages([])
54
42
  self.collection_images.set_pbar(pbar)
55
43
  self.collection_pages.set_pbar(pbar)
56
44
  self.lib_pdf: LibPDF = lib_pdf
@@ -61,7 +49,7 @@ class PdfStream(object):
61
49
 
62
50
  @property
63
51
  def is_empty(self) -> bool:
64
- return self.collection_pages.is_null
52
+ return self.collection_pages.is_empty
65
53
 
66
54
  def set_land_scape(self):
67
55
  self.collection_pages.set_land_scape()
@@ -109,28 +97,28 @@ class PdfStream(object):
109
97
 
110
98
  def to_document(self, *, land_scape: bool = False, a4: bool = False) -> DocumentPdf:
111
99
  """
112
-
113
100
  Converte os documentos adicionados em PdfStream (imagens/pdfs) em
114
101
  objeto do tipo DocumentPdf().
115
102
  """
116
- if self.collection_pages.is_null and self.collection_images.is_empty:
103
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
117
104
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
118
105
 
119
- _doc = None
106
+ _doc: DocumentPdf = None
120
107
  if not self.collection_images.is_empty:
121
108
  _convert = ConvertImageToPdf(self.collection_images, lib_img_to_pdf=self.lib_img_to_pdf)
109
+ _convert.set_pbar(self.progress)
122
110
  _doc: DocumentPdf = _convert.to_document(land_scape, a4=a4)
123
- if not self.collection_pages.is_null:
111
+ if not self.collection_pages.is_empty:
124
112
  if _doc is None:
125
113
  _doc: DocumentPdf = self.collection_pages.to_document(self.lib_pdf)
126
114
  else:
127
- _doc.add_pages(self.collection_pages.pages)
115
+ _doc.add_pages(self.collection_pages)
128
116
  return _doc
129
117
 
130
118
  def thresold(self, *, land_scape: bool = False, a4: bool = False, dpi=300) -> DocumentPdf:
131
- images: list[ImageObject] = self.collection_images.images
132
- if not self.collection_pages.is_null:
133
- tmp_doc = DocumentPdf.create_from_pages(self.collection_pages.pages)
119
+ images: list[ImageObject] = self.collection_images
120
+ if not self.collection_pages.is_empty:
121
+ tmp_doc = DocumentPdf.create_from_pages(self.collection_pages)
134
122
  conv_pdf_to_img = ConvertPdfToImages.create(tmp_doc)
135
123
  images.extend(conv_pdf_to_img.to_images(dpi=dpi))
136
124
  del tmp_doc
@@ -151,17 +139,17 @@ class PdfStream(object):
151
139
  land_scape: bool = False,
152
140
  dpi: int = 300,
153
141
  ) -> None:
154
- if self.collection_pages.is_null and self.collection_images.is_empty:
142
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
155
143
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
156
144
  self.progress.start()
157
145
 
158
- image_stream = ImageStream()
146
+ image_stream = ImageStream([])
159
147
  if not self.collection_images.is_empty:
160
- image_stream.add_images(self.collection_images.images)
161
- if not self.collection_pages.is_null:
148
+ image_stream.add_images(self.collection_images)
149
+ if not self.collection_pages.is_empty:
162
150
  self.progress.update_text('Processando Imagens')
163
151
  # Criar um documento a partir das páginas
164
- doc_pdf = DocumentPdf.create_from_pages(self.collection_pages.pages)
152
+ doc_pdf = DocumentPdf.create_from_pages(self.collection_pages)
165
153
  convert_pdf_to_img = ConvertPdfToImages.create(doc_pdf)
166
154
  # Converter as páginas PDF em imagens e adicionar a coleção já existe de imagens.
167
155
  _pdf_to_images: list[ImageObject] = convert_pdf_to_img.to_images(dpi=dpi)
@@ -178,11 +166,11 @@ class PdfStream(object):
178
166
  a4: bool = False,
179
167
  prefix: str = None,
180
168
  ) -> None:
181
- if self.collection_pages.is_null and self.collection_images.is_empty:
169
+ if self.collection_pages.is_empty and self.collection_images.is_empty:
182
170
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
183
171
  pages_document = []
184
- if not self.collection_pages.is_null:
185
- pages_document.extend(self.collection_pages.pages)
172
+ if not self.collection_pages.is_empty:
173
+ pages_document.extend(self.collection_pages)
186
174
  if not self.collection_images.is_empty:
187
175
  img_to_pdf = ConvertImageToPdf(self.collection_images, lib_img_to_pdf=self.lib_img_to_pdf)
188
176
  tmp_document = img_to_pdf.to_document(land_scape, a4=a4)
@@ -201,7 +189,7 @@ class SplitPdf(object):
201
189
  self.__collection_pages.set_pbar(self.pbar)
202
190
 
203
191
  def is_empty(self) -> bool:
204
- return self.__collection_pages.is_null
192
+ return self.__collection_pages.is_empty
205
193
 
206
194
  def add_pages_pdf(self, pages: list[PageDocumentPdf]) -> None:
207
195
  self.__collection_pages.add_pages(pages)
@@ -212,6 +200,3 @@ class SplitPdf(object):
212
200
  return
213
201
  self.__collection_pages.to_files_pdf(output_dir, replace=replace, prefix=prefix)
214
202
  self.__collection_pages.clear()
215
-
216
-
217
-
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from .img_object import ImageObject, CollectionImages
4
+ __all__ = ['ImageObject', 'CollectionImages']
5
+
6
+
7
+
@@ -6,29 +6,31 @@
6
6
  from __future__ import annotations
7
7
  from typing import Union
8
8
  from abc import ABC, abstractmethod
9
- from hashlib import md5 as md5_hash
10
9
  from soup_files import File, Directory, InputFiles, LibraryDocs, ProgressBarAdapter
11
10
  from io import BytesIO
12
11
  import numpy as np
13
12
  from scipy.ndimage import uniform_filter
14
- from convert_stream.enum_libs.enums import LibImage, RotationAngle
15
- from convert_stream.enum_libs.modules import (
13
+ from convert_stream.mod_types import get_void_metadata, get_hash_from_bytes
14
+ from convert_stream.mod_types.enums import LibImage, RotationAngle
15
+ from convert_stream.mod_types.table_types import ListItems
16
+ from convert_stream.mod_types.modules import (
16
17
  MOD_IMG_PIL, ModuleImage, DEFAULT_LIB_IMAGE,
17
18
  cv2, MatLike, Image, ImageFilter
18
19
  )
19
20
 
20
21
 
21
- def get_hash_from_bytes(bt: BytesIO) -> str:
22
- return md5_hash(bt.getvalue()).hexdigest().upper()
23
-
24
-
25
22
  class ABCImageObject(ABC):
26
23
 
27
- def __init__(self, module_image: ModuleImage, name: str) -> None:
28
- self.max_size: tuple[int, int] = (1980, 720) # Dimensões máximas, altere se necessário.
24
+ def __init__(self, module_image: ModuleImage) -> None:
25
+ # Dimensões máximas, altere se necessário.
26
+ self.max_size: tuple[int, int] = (1980, 720)
29
27
  self.module_image: ModuleImage = module_image
30
28
  self.lib_image: LibImage = LibImage.OPENCV
31
- self.name: str = name
29
+ self.metadata: dict[str, str | None] = get_void_metadata()
30
+
31
+ @property
32
+ def name(self) -> str | None:
33
+ return self.metadata['name']
32
34
 
33
35
  @abstractmethod
34
36
  def get_dimensions(self) -> tuple[int, int]:
@@ -89,8 +91,8 @@ class ABCImageObject(ABC):
89
91
 
90
92
 
91
93
  class ImplementOpenCv(ABCImageObject):
92
- def __init__(self, module_image: ModuleImage, name: str) -> None:
93
- super().__init__(module_image, name)
94
+ def __init__(self, module_image: ModuleImage) -> None:
95
+ super().__init__(module_image)
94
96
  self.lib_image = LibImage.OPENCV
95
97
 
96
98
  # Redimensionar se necessário
@@ -202,7 +204,13 @@ class ImplementOpenCv(ABCImageObject):
202
204
  img = cv2.imread(f.absolute())
203
205
  if img is None:
204
206
  raise ValueError(f"Não foi possível abrir a imagem: {f.absolute()}")
205
- return cls(img, f.name())
207
+ im_obj = cls(img)
208
+ im_obj.metadata['file_path'] = f.absolute()
209
+ im_obj.metadata['md5'] = f.md5()
210
+ im_obj.metadata['name'] = f.absolute()
211
+ im_obj.metadata['size'] = f.size()
212
+ im_obj.metadata['extension'] = f.extension()
213
+ return im_obj
206
214
 
207
215
  @classmethod
208
216
  def create_from_bytes(cls, bt: bytes) -> ABCImageObject:
@@ -211,14 +219,17 @@ class ImplementOpenCv(ABCImageObject):
211
219
  if img is None:
212
220
  raise ValueError("Não foi possível criar a imagem a partir dos bytes fornecidos.")
213
221
  bytes_io = BytesIO(bt)
214
- name = get_hash_from_bytes(bytes_io)
222
+ name: str = get_hash_from_bytes(bytes_io)
215
223
  bytes_io.close()
216
- return cls(img, name)
224
+ _obj = cls(img)
225
+ _obj.metadata['md5'] = name
226
+ _obj.metadata['name'] = name
227
+ return _obj
217
228
 
218
229
 
219
230
  class ImplementPIL(ABCImageObject):
220
- def __init__(self, module_image: ModuleImage, name: str):
221
- super().__init__(module_image, name)
231
+ def __init__(self, module_image: ModuleImage):
232
+ super().__init__(module_image)
222
233
  self.lib_image = LibImage.PIL
223
234
 
224
235
  # Redimensionar, se as dimensões estiverem maior que self.max_size.
@@ -342,7 +353,13 @@ class ImplementPIL(ABCImageObject):
342
353
  @classmethod
343
354
  def create_from_file(cls, f: File) -> ABCImageObject:
344
355
  img = Image.open(f.path)
345
- return cls(img, f.name())
356
+ im_obj = cls(img)
357
+ im_obj.metadata['file_path'] = f.absolute()
358
+ im_obj.metadata['md5'] = f.md5()
359
+ im_obj.metadata['name'] = f.absolute()
360
+ im_obj.metadata['size'] = f.size()
361
+ im_obj.metadata['extension'] = f.extension()
362
+ return im_obj
346
363
 
347
364
  @classmethod
348
365
  def create_from_bytes(cls, bt: bytes) -> ABCImageObject:
@@ -350,7 +367,10 @@ class ImplementPIL(ABCImageObject):
350
367
  bytes_io = BytesIO(bt)
351
368
  name = get_hash_from_bytes(bytes_io)
352
369
  bytes_io.close()
353
- return cls(img, name)
370
+ _obj = cls(img)
371
+ _obj.metadata['md5'] = name
372
+ _obj.metadata['name'] = name
373
+ return _obj
354
374
 
355
375
 
356
376
  class ImageObject(object):
@@ -398,6 +418,10 @@ class ImageObject(object):
398
418
  def name(self) -> str:
399
419
  return self.img_adapter.name
400
420
 
421
+ @property
422
+ def metadata(self) -> dict[str, str | None]:
423
+ return self.img_adapter.metadata
424
+
401
425
  def to_pil(self) -> Image.Image:
402
426
  """
403
427
  Converte o ImageObject para um objeto PIL.Image.
@@ -473,44 +497,35 @@ class ImageObject(object):
473
497
 
474
498
  @classmethod
475
499
  def create_from_pil(cls, pil: ModuleImage) -> ImageObject:
476
- name = get_hash_from_bytes(BytesIO(pil.tobytes()))
477
- return cls(ImplementPIL(pil, name))
500
+ return cls(ImplementPIL(pil))
478
501
 
479
502
 
480
- class CollectionImages(object):
503
+ class CollectionImages(ListItems):
481
504
 
482
- def __init__(self, images: list[ImageObject] = []) -> None:
505
+ def __init__(self, images: list[ImageObject]) -> None:
483
506
  """
484
507
  Gerir uma lista de Imagens
485
508
  :type images: list[ImageObject]
486
509
  """
487
- self.images: list[ImageObject] = images
510
+ super().__init__(images)
488
511
  self.pbar: ProgressBarAdapter = ProgressBarAdapter()
489
512
  self.__count: int = 0
490
513
 
491
- @property
492
- def length(self) -> int:
493
- return len(self.images)
494
-
495
- @property
496
- def is_empty(self) -> bool:
497
- return len(self.images) == 0
498
-
499
514
  def clear(self) -> None:
500
- self.images.clear()
515
+ self.clear()
501
516
  self.__count = 0
502
517
 
503
518
  def add_image(self, image: ImageObject) -> None:
504
519
  self.__count += 1
505
520
  self.pbar.update_text(f'Adicionando imagem {self.__count}')
506
- self.images.append(image)
521
+ self.append(image)
507
522
 
508
523
  def add_file_image(self, file: File) -> None:
509
524
  self.pbar.start()
510
525
  self.__count += 1
511
526
  self.pbar.update_text(f'Adicionando imagem {self.__count} {file.basename()}')
512
527
  im = ImageObject.create_from_file(file)
513
- self.images.append(im)
528
+ self.append(im)
514
529
  self.pbar.stop()
515
530
 
516
531
  def add_images(self, images: list[ImageObject]) -> None:
@@ -525,7 +540,7 @@ class CollectionImages(object):
525
540
  ((num+1) / max_num) * 100,
526
541
  f'Adicionando imagem: [{num+1} de {max_num}]'
527
542
  )
528
- self.images.append(ImageObject.create_from_file(f))
543
+ self.append(ImageObject.create_from_file(f))
529
544
  self.pbar.stop()
530
545
 
531
546
  def add_directory_images(self, d: Directory, max_files: int = 4000) -> None:
@@ -542,8 +557,8 @@ class CollectionImages(object):
542
557
  self.pbar.start()
543
558
  print()
544
559
  output_dir.mkdir()
545
- max_num = len(self.images)
546
- for n, img in enumerate(self.images):
560
+ max_num = self.length
561
+ for n, img in enumerate(self):
547
562
  filename = f'{img.name}.png'
548
563
  file_path = output_dir.join_file(filename)
549
564
  if (not replace) and (file_path.exists()):
@@ -566,13 +581,13 @@ class CollectionImages(object):
566
581
  self.pbar.stop()
567
582
 
568
583
  def set_land_scape(self):
569
- for im in self.images:
584
+ for im in self:
570
585
  im.set_landscape()
571
586
 
572
587
  def set_gausian_blur(self, sigma: float = 0.8) -> None:
573
588
  self.pbar.start()
574
589
  max_num: int = self.length
575
- for _num, im in enumerate(self.images):
590
+ for _num, im in enumerate(self):
576
591
  self.pbar.update(
577
592
  ((_num + 1) / max_num) * 100,
578
593
  f'Aplicando GausianBlur: [{_num + 1} de {max_num}]'
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ from __future__ import annotations
4
+ from hashlib import md5 as md5_hash
5
+ from io import BytesIO
6
+ from .table_types import (
7
+ TextTable, ColumnsTable, ListString, ArrayString, HeadCell, HeadValues,
8
+ ColumnBody, create_void_map, create_map_from_values, create_void_table,
9
+ create_map_from_file_values, concat_maps, contains, get_text_from_file
10
+ )
11
+
12
+
13
+ def get_hash_from_bytes(bt: BytesIO | bytes) -> str:
14
+ if isinstance(bt, BytesIO):
15
+ return md5_hash(bt.getvalue()).hexdigest().upper()
16
+ elif isinstance(bt, bytes):
17
+ return md5_hash(bt).hexdigest().upper()
18
+ else:
19
+ raise TypeError(f"Unsupported type {type(bt)}")
20
+
21
+
22
+ def get_void_metadata() -> dict[str, str | None]:
23
+ """
24
+ Salvar os metadados básico de documentos/imagens lidas em disco.
25
+ """
26
+ return {
27
+ 'file_path': None,
28
+ 'dir_path': None,
29
+ 'name': None,
30
+ 'md5': None,
31
+ 'size': None,
32
+ 'extension': None,
33
+ 'origin_src': None,
34
+ }
35
+
36
+
37
+ __all__ = [
38
+ 'get_hash_from_bytes', 'get_void_metadata', 'get_void_metadata', 'contains',
39
+ 'concat_maps', 'create_map_from_file_values', 'create_map_from_values',
40
+ 'create_void_table', 'create_void_map', 'ColumnBody', 'ColumnsTable',
41
+ 'ListString', 'HeadCell', 'HeadValues', 'TextTable',
42
+ ]
@@ -1,33 +1,37 @@
1
1
  #!/usr/bin/env python3
2
-
3
2
  from enum import Enum
4
3
 
5
4
 
6
5
  class ColumnsTable(Enum):
6
+ """
7
+ Classe enum para padronizar os nomes das tabelas geradas por este módulo.
8
+ """
7
9
 
8
- NUM_LINHA = 'NUM_LINHA'
9
- NUM_PAGE = 'NUM_PÁGINA'
10
+ NUM_LINE = 'LINHA'
11
+ NUM_PAGE = 'PÁGINA'
10
12
  TEXT = 'TEXTO'
11
- FILE = 'ARQUIVO'
12
- FILENAME = 'NOME_ARQUIVO'
13
+ FILE_PATH = 'ARQUIVO'
14
+ FILE_NAME = 'NOME_ARQUIVO'
13
15
  DIR = 'PASTA'
14
16
  FILETYPE = 'TIPO_ARQUIVO'
17
+ KEY = 'KEY'
15
18
 
16
19
  @classmethod
17
20
  def to_list(cls) -> list[str]:
18
21
  return [
19
- cls.NUM_LINHA.value,
22
+ cls.NUM_LINE.value,
20
23
  cls.NUM_PAGE.value,
21
24
  cls.TEXT.value,
22
- cls.FILE.value,
23
- cls.FILENAME.value,
25
+ cls.FILE_PATH.value,
26
+ cls.FILE_NAME.value,
24
27
  cls.FILETYPE.value,
25
28
  cls.DIR.value,
29
+ cls.KEY.value,
26
30
  ]
27
31
 
28
32
 
29
33
  class LibPdfToImage(Enum):
30
-
34
+ """Enumerar as bibliotecas externas que convertem PDF em imagem"""
31
35
  PDF_TO_IMG_FITZ = 'fitz'
32
36
  NOT_IMPLEMENTED = 'null'
33
37
 
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
  from __future__ import annotations
4
- from typing import Union, TypeAlias #, Any
5
- from convert_stream.enum_libs.enums import *
4
+ from typing import Union, TypeAlias
5
+ from convert_stream.mod_types.enums import *
6
6
 
7
7
  MOD_IMG_PIL: bool = False
8
8
  MOD_IMG_OPENCV: bool = False
@@ -29,7 +29,6 @@ try:
29
29
  from cv2.typing import MatLike
30
30
  MOD_IMG_OPENCV = True
31
31
  except ImportError:
32
- #cv2.typing.MatLike = FakeType
33
32
  MatLike = FakeType
34
33
 
35
34
  try:
@@ -51,7 +50,7 @@ elif MOD_IMG_PIL:
51
50
  DEFAULT_LIB_IMAGE = LibImage.PIL
52
51
  else:
53
52
  DEFAULT_LIB_IMAGE = LibImage.NOT_IMPLEMENTED
54
- ModuleImage = FakeType # fallback para runtime
53
+ ModuleImage = FakeType
55
54
 
56
55
  #=================================================================#
57
56
  # Módulos para PDF fitz e pypdf