csc-cia-stne 0.0.68__py3-none-any.whl → 0.0.70__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.
@@ -256,9 +256,9 @@ class GoogleDrive:
256
256
  except Exception as e:
257
257
  return {"success": False, "result": None, "error": str(e)}
258
258
 
259
- def download_file(self, file: str, mimeType: str):
259
+ def download_google_files(self, file: str, mimeType: str, path: str):
260
260
  """
261
- Obtém o conteúdo de um arquivo armazenado no Google Drive.
261
+ Obtém o conteúdo de um arquivo armazenado no Google Drive. Aceito somente para extensões Google
262
262
 
263
263
  Esta função acessa o Google Drive usando a API e lê os dados do arquivo especificado, retornando-os como um objeto binário de memória (`BytesIO`).
264
264
 
@@ -281,15 +281,63 @@ class GoogleDrive:
281
281
  Dependências:
282
282
  - A função assume a existência de um atributo `self.service` configurado para interagir com a API do Google Drive.
283
283
  """
284
+ if not os.path.exists(path):
285
+ os.makedirs(path)
284
286
  try:
285
287
  request = self.service.files().export_media(
286
288
  fileId=file.get("id"), mimeType=mimeType
287
289
  )
290
+ file_path = f"{path}{file["name"]}"
288
291
  with open(file["name"], "wb") as f:
289
292
  f.write(request.execute())
290
293
  return {
291
294
  "success": True,
292
- "result": f"Arquivo baixado com sucesso. Diretório: {file}",
295
+ "result": file_path,
296
+ }
297
+
298
+ except Exception as e:
299
+ return {"success": False, "result": None}
300
+
301
+ def download_others_files(self, file: str, path: str):
302
+ """
303
+ Obtém o conteúdo de um arquivo armazenado nos seguintes formatos:
304
+ .xlsx, .pdf, .jpg, etc.
305
+
306
+ Esta função acessa o Google Drive usando a API e lê os dados do arquivo especificado, retornando-os como um objeto binário de memória (`BytesIO`).
307
+
308
+ Parâmetros:
309
+ - file (str): Dicionário contendo informações do arquivo no Google Drive, incluindo as chaves:
310
+ - `"name"`: Nome do arquivo.
311
+ - `"id"`: ID do arquivo.
312
+ - mimeType (str): Tipo do arquivo, por exemplo: xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
313
+ - path (str): diretório onde será salvo o arquivo.
314
+
315
+ Retorna:
316
+ - BytesIO: Objeto em memória contendo os dados do arquivo.
317
+ - None: Caso ocorra um erro ao tentar abrir ou ler o arquivo.
318
+
319
+ Logs:
320
+ - Registra mensagens indicando o início e o término da leitura do arquivo.
321
+ - Em caso de falha, registra o erro ocorrido.
322
+
323
+ Exceções:
324
+ - Qualquer erro durante o processo será capturado e registrado no log. A função retornará `None` nesses casos.
325
+
326
+ Dependências:
327
+ - A função assume a existência de um atributo `self.service` configurado para interagir com a API do Google Drive.
328
+ """
329
+ if not os.path.exists(path):
330
+ os.makedirs(path)
331
+ try:
332
+ request = self.service.files().get_media(
333
+ fileId=file.get("id")
334
+ )
335
+ file_path = f"{path}{file["name"]}"
336
+ with open(file_path, "wb") as f:
337
+ f.write(request.execute())
338
+ return {
339
+ "success": True,
340
+ "result": file_path,
293
341
  }
294
342
 
295
343
  except Exception as e:
@@ -6,114 +6,6 @@ from rich.traceback import install
6
6
  import re
7
7
  import traceback
8
8
  import os
9
- """
10
- # Instala formatações de exception da biblioteca Rich
11
- install()
12
-
13
- # Definindo o nível de log baseado nas configurações
14
- if os.getenv('log_level') is None:
15
-
16
- log_config_level = logging.DEBUG
17
-
18
- elif os.getenv('log_level') == "DEBUG":
19
-
20
- log_config_level = logging.DEBUG
21
-
22
- elif os.getenv('log_level') == "INFO":
23
-
24
- log_config_level = logging.INFO
25
-
26
- else:
27
-
28
- log_config_level = logging.WARNING # ou outro nível padrão
29
-
30
- # Definindo o tema customizado
31
- custom_theme = Theme({
32
- # python -m rich.color - cores
33
- # python -m rich.default_styles - item + cor padrão
34
- "logging.level.debug": "bold bright_cyan",
35
- "logging.level.info": "bold bright_white",
36
- "logging.level.warning": "bold orange1",
37
- "logging.level.error": "bold red blink",
38
- "logging.level.critical": "bold white on red blink",
39
- "logging.level.success": "bold bright_green",
40
- "log.time":"bold white",
41
- "log.message":"bold gray70",
42
- "repr.str":"dark_olive_green3",
43
- "inspect.value.border":"blue",
44
- })
45
-
46
- console = Console(theme=custom_theme)
47
-
48
- class CustomRichHandler(RichHandler):
49
- def __init__(self, *args, rich_tracebacks=True, show_time=True, show_level=True, show_path=True, console=console, omit_repeated_times=True, **kwargs):
50
- super().__init__(rich_tracebacks=rich_tracebacks, show_time=show_time, show_level=show_level, show_path=show_path, console=console, omit_repeated_times=omit_repeated_times, *args, **kwargs)
51
- self.show_time = show_time
52
-
53
-
54
- def format(self, record: logging.LogRecord) -> str:
55
- try:
56
- msg = f"| {record.getMessage()}"
57
- #msg = f"{record.getMessage()}"
58
-
59
- return(str(msg))
60
- except Exception as e:
61
- print("FALHA AO FORMATAR O LOG")
62
- print(e)
63
-
64
- # Configurando o logging com o CustomRichHandler
65
- logging.basicConfig(
66
- level=log_config_level,
67
- handlers=[CustomRichHandler()],
68
- datefmt="%d/%m/%Y %H:%M:%S |",
69
- format="| %(message)s"
70
- )
71
-
72
- def add_log_level(level_name, level_num, method_name=None):
73
- #""
74
- #Adiciona um log level
75
- #
76
- #Parâmetros:
77
- # level_name (str): Nome do level
78
- # level_num (int): Número do level
79
- #""
80
- if not method_name:
81
-
82
- method_name = level_name.lower()
83
-
84
- if hasattr(logging, level_name):
85
-
86
- raise AttributeError('{} already defined in logging module'.format(level_name))
87
-
88
- if hasattr(logging, method_name):
89
-
90
- raise AttributeError('{} already defined in logging module'.format(method_name))
91
-
92
- if hasattr(logging.getLoggerClass(), method_name):
93
-
94
- raise AttributeError('{} already defined in logger class'.format(method_name))
95
-
96
- def log_for_level(self, message, *args, **kwargs):
97
-
98
- if self.isEnabledFor(level_num):
99
-
100
- #self._log(level_num, message, args, **kwargs)
101
- self._log(level_num, message, args, **{**kwargs, "stacklevel": 2})
102
-
103
- def log_to_root(message, *args, **kwargs):
104
-
105
- logging.log(level_num, message, *args, **kwargs)
106
-
107
- logging.addLevelName(level_num, level_name)
108
- setattr(logging, level_name, level_num)
109
- setattr(logging.getLoggerClass(), method_name, log_for_level)
110
- setattr(logging, method_name, log_to_root)
111
-
112
- add_log_level("SUCCESS",21)
113
-
114
- logger = logging.getLogger()
115
-
116
- """
117
9
 
118
10
  def get_logger(nome):
119
11
  """
@@ -172,7 +64,7 @@ def get_logger(nome):
172
64
 
173
65
  class CustomRichHandler(RichHandler):
174
66
  def __init__(self, *args, rich_tracebacks=True, show_time=True, show_level=True, show_path=True, console=console, omit_repeated_times=True, **kwargs):
175
- super().__init__(rich_tracebacks=rich_tracebacks, show_time=show_time, show_level=show_level, show_path=show_path, console=console, omit_repeated_times=omit_repeated_times, *args, **kwargs)
67
+ super().__init__(rich_tracebacks=rich_tracebacks, show_time=show_time, log_time_format="%d/%m/%Y %H:%M:%S", show_level=show_level, show_path=show_path, console=console, omit_repeated_times=omit_repeated_times, *args, **kwargs)
176
68
  self.show_time = show_time
177
69
 
178
70
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: csc_cia_stne
3
- Version: 0.0.68
3
+ Version: 0.0.70
4
4
  Summary: Biblioteca do time CSC-CIA utilizada no desenvolvimento de RPAs
5
5
  License: MIT
6
6
  Keywords: karavela,csc,cia,stone,rpa,botcity,stne
@@ -3,10 +3,10 @@ csc_cia_stne/bc_correios.py,sha256=pQAnRrcXEMrx3N1MWydZVIhEQLerh3x8-0B045zZIzk,2
3
3
  csc_cia_stne/bc_sta.py,sha256=KWHTytM3msAFayt8y5_97RwWHE8Dv8ssfwyh6zU7xI0,25836
4
4
  csc_cia_stne/email.py,sha256=RK_TzWBVnUfpP-s5NvjTJJjzhICy8e2fME9EuaiySMY,8162
5
5
  csc_cia_stne/gcp_bigquery.py,sha256=jYxvqrWDOPkxc05U4aef7V5lL8ptqsE93lfn0dLFyvc,7385
6
- csc_cia_stne/google_drive.py,sha256=0gZMW69jEvBMcUl3s9qaL5-q2IXOEAghnfhXp6-6ooY,12357
6
+ csc_cia_stne/google_drive.py,sha256=OeBIliKZUxSBcOQwBfAdaQMKChWVWaEudMUDuc1rjU4,14399
7
7
  csc_cia_stne/karavela.py,sha256=jJCYX43D49gGuzmwwK6bN9XVnv2dXdp9iHnnV5H1LMQ,4794
8
8
  csc_cia_stne/logger_json.py,sha256=CXxSCOFGMymDi8XE9SKnPKjW4D0wJLqDLnxqePS26i8,3187
9
- csc_cia_stne/logger_rich.py,sha256=WlMqxH1lMy-tzK0I4NpBRgSzPdHc2-YSU71N3SsKM5A,8338
9
+ csc_cia_stne/logger_rich.py,sha256=d6tL7f7Yldg3eivNWRiwRTwT0i5w68aeMRfrQoNRHVQ,5072
10
10
  csc_cia_stne/provio.py,sha256=G-pDnHYLSp97joc7S7dvwjNvl3omnTmvdi3rOPQf5GA,3987
11
11
  csc_cia_stne/servicenow.py,sha256=cJtNtLZ8glWfs3OAzl78ZFlPyPz39CSBxHqpTdUU7i0,32136
12
12
  csc_cia_stne/slack.py,sha256=33_UNF7M529eIuWjmzSJFEZ4RmVNkFkuVxvxwsKY1tQ,8126
@@ -26,8 +26,8 @@ csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=PBo-AV2bjR__
26
26
  csc_cia_stne/utilitarios/validations/ServiceNowValidator.py,sha256=yleKUIo1ZfyloP9fDPNjv3JJXdLcocT81WIgRSYmqEA,14423
27
27
  csc_cia_stne/utilitarios/validations/__init__.py,sha256=O_qyEU2ji3u6LHUXZCXvUFsMpoMWL625qqHTXyXivTA,106
28
28
  csc_cia_stne/utilitarios/validations/web_validator.py,sha256=HYKYSpDv1RvRjZIuwTPt-AbEz-9392MxM_O329iYuSA,5722
29
- csc_cia_stne-0.0.68.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
30
- csc_cia_stne-0.0.68.dist-info/METADATA,sha256=Rtr1P2z_LC8R8NSeqCtJhMZFF_AYCi0vYjPwMSRGBUo,1340
31
- csc_cia_stne-0.0.68.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
32
- csc_cia_stne-0.0.68.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
33
- csc_cia_stne-0.0.68.dist-info/RECORD,,
29
+ csc_cia_stne-0.0.70.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
30
+ csc_cia_stne-0.0.70.dist-info/METADATA,sha256=_kgUcgPevyIlWDAk4umBHaXF98I7fUq3YBQneKMZVwQ,1340
31
+ csc_cia_stne-0.0.70.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
32
+ csc_cia_stne-0.0.70.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
33
+ csc_cia_stne-0.0.70.dist-info/RECORD,,