csc-cia-stne 0.0.58__py3-none-any.whl → 0.0.60__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.
@@ -227,7 +227,7 @@ class GoogleDrive():
227
227
  logging.error(f"Ocorreu um erro ao fazer a requisição. Error: {e}")
228
228
 
229
229
 
230
- def get_file(self, file : str, ):
230
+ def download_file(self, file : str, mimeType : str):
231
231
  """
232
232
  Obtém o conteúdo de um arquivo armazenado no Google Drive.
233
233
 
@@ -253,16 +253,37 @@ class GoogleDrive():
253
253
  - A função assume a existência de um atributo `self.service` configurado para interagir com a API do Google Drive.
254
254
  """
255
255
  try:
256
- logging.debug(f"Lendo o arquivo {file.get('name')}")
257
- request = self.service.files().get_media(fileId=file.get("id"))
258
- file_data = BytesIO(request.execute())
259
- logging.debug("Leitura do arquivo finalizada")
260
-
261
- return {"success" : True, "result" : file_data}
256
+ request = self.service.files().export_media(fileId=file.get("id"), mimeType=mimeType)
257
+ with open (file["name"], "wb") as f:
258
+ f.write(request.execute())
259
+ return {"success" : True, "result" : f"Arquivo baixado com sucesso. Diretório: {file}"}
262
260
 
263
261
  except Exception as e:
264
262
  logging.debug(f"Erro ao tentar abrir o arquivo. Erro {e}")
265
263
  return {"success" : False, "result" : None}
264
+
266
265
 
266
+ def get_base_data(self, id_sheet:str,page:str) -> list:
267
+ """
268
+ Retorna os dados da planilha especificada.
269
+ Parâmetros:
270
+ - drive_client: Cliente do Google Drive.
271
+ - id_sheet: ID da planilha.
272
+ - page: Nome da página da planilha.
273
+ Retorna:
274
+ - Uma lista contendo os valores da planilha.
275
+ Exemplo de uso:
276
+ >>> drive_client = ...
277
+ >>> id_sheet = "abc123"
278
+ >>> page = "Sheet1"
279
+ >>> data = get_base_data(drive_client, id_sheet, page)
280
+ """
281
+ try:
282
+ sheet = self.service.spreadsheets()
283
+ result = sheet.values().get(spreadsheetId=id_sheet, range=page).execute()
284
+ values = result.get('values', [])
285
+ return {"success" : True, "result" : values}
286
+ except Exception as e:
287
+ return {"success" : False, "result" : None, "error" : str(e)}
267
288
 
268
289
 
@@ -4,6 +4,7 @@ from .func_b64 import b64decode, b64encode
4
4
  from .func_converters import convert_bquery_result_to_json
5
5
  from .func_settings import get_config
6
6
  from .func_get_secret import get_secret
7
+ from .func_rdp import obter_ip_conexao_rdp, conectar_rdp
7
8
 
8
9
  __all__ = [
9
10
  "titulo",
@@ -12,5 +13,7 @@ __all__ = [
12
13
  "b64decode",
13
14
  "convert_bquery_result_to_json",
14
15
  "get_config",
15
- "get_secret"
16
+ "get_secret",
17
+ "obter_ip_conexao_rdp",
18
+ "conectar_rdp"
16
19
  ]
@@ -0,0 +1,103 @@
1
+ import platform
2
+ import subprocess
3
+ import time
4
+ import pyautogui
5
+ import psutil
6
+ import logging
7
+
8
+ def obter_ip_conexao_rdp():
9
+ """Retorna o ip da conexão RDP
10
+
11
+ Returns:
12
+ str: ip
13
+ """
14
+
15
+ for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
16
+
17
+ if proc.info['name'] == 'mstsc.exe' and proc.info['cmdline']:
18
+
19
+ for arg in proc.info['cmdline']:
20
+
21
+ if arg.startswith("/v:"): # O argumento '/v:' contém o IP
22
+
23
+ return arg.replace("/v:", "").strip()
24
+
25
+ return None
26
+
27
+ def conectar_rdp(host, usuario, senha):
28
+ """Conecta via RDP em uma máquina remota
29
+
30
+ Args:
31
+
32
+ host (str): ip/host destino
33
+ usuario (str): usuário
34
+ senha (str): senha
35
+
36
+ Returns:
37
+ bool: True/False
38
+ """
39
+
40
+ sistema = platform.system()
41
+
42
+ if sistema == "Windows":
43
+
44
+ try:
45
+
46
+ # Inicia o mstsc
47
+ cmd_conexao = f"start mstsc /v:{host} /f"
48
+ subprocess.run(cmd_conexao, shell=True)
49
+
50
+ # Aguarda um tempo para verificar se a conexão foi feita
51
+ time.sleep(3) # Dá tempo para o usuário tentar logar
52
+ pyautogui.typewrite(senha)
53
+ pyautogui.press('enter')
54
+ time.sleep(2)
55
+ pyautogui.press('left')
56
+ pyautogui.press('enter')
57
+ time.sleep(5)
58
+ return True
59
+
60
+ except Exception as e:
61
+
62
+ logging.error(f"Falha ao tentar logar via RDP (Windows)\nErro: {str(e)}")
63
+ return False
64
+
65
+ elif sistema == "Linux":
66
+
67
+ # Comando para executar a conexao com o xfreerdp
68
+ # Para instalar: sudo apt install freerdp2-x11
69
+ comando_rdp = f"""xfreerdp /u:{usuario} /p:{senha} /v:{host} /size:1920x1080"""
70
+
71
+ # Executar o comando e capturar saída
72
+ try:
73
+
74
+ processo_rdp = subprocess.Popen(
75
+ comando_rdp,
76
+ shell=True,
77
+ stdout=subprocess.PIPE,
78
+ stderr=subprocess.PIPE,
79
+ text=True
80
+ )
81
+
82
+ except Exception as e:
83
+
84
+ raise Exception(f"Falha ao executar o comando de conexão RDP no Linux. Você possui o xfreerdp instalado? (sudo apt install freerdp2-x11)\nErro: {str(e)}")
85
+
86
+ # Aguarda 10 segundos, para aparecer o banner azul
87
+ time.sleep(10)
88
+
89
+ # Se a conexão foi bem-sucedida, retornar True
90
+ if processo_rdp.poll() is None:
91
+
92
+ # Clica no 'enter', no banner azul
93
+ pyautogui.press('enter')
94
+ return True
95
+
96
+ else:
97
+
98
+ return False
99
+
100
+ else:
101
+
102
+ raise Exception("Sistema operacional não suportado (Somente 'Windows' ou 'Linux').")
103
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: csc_cia_stne
3
- Version: 0.0.58
3
+ Version: 0.0.60
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
@@ -26,6 +26,7 @@ Requires-Dist: webdriver-manager
26
26
  Requires-Dist: botcity-framework-web
27
27
  Requires-Dist: email-validator
28
28
  Requires-Dist: botcity-maestro-sdk
29
+ Requires-Dist: psutil
29
30
 
30
31
  Essa biblioteca é desenvolvida e atualizada pelo time **CSC-CIA** da **Stone**
31
32
 
@@ -3,7 +3,7 @@ csc_cia_stne/bc_correios.py,sha256=pQAnRrcXEMrx3N1MWydZVIhEQLerh3x8-0B045zZIzk,2
3
3
  csc_cia_stne/bc_sta.py,sha256=f75HJ7FLIDSJFLDTvvSvCYo9z0HchzP7rDY5WIdiKXY,16830
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=JcXKlRBSxf5CKM-alT4ZpqWVWLZQfIYIX42_nENoTgU,11896
6
+ csc_cia_stne/google_drive.py,sha256=lgcOd27vk2Mb_wP_fAWIbec-S3MIBKyh4TpRth6REXc,12788
7
7
  csc_cia_stne/karavela.py,sha256=jJCYX43D49gGuzmwwK6bN9XVnv2dXdp9iHnnV5H1LMQ,4794
8
8
  csc_cia_stne/logger_json.py,sha256=CXxSCOFGMymDi8XE9SKnPKjW4D0wJLqDLnxqePS26i8,3187
9
9
  csc_cia_stne/logger_rich.py,sha256=WlMqxH1lMy-tzK0I4NpBRgSzPdHc2-YSU71N3SsKM5A,8338
@@ -13,10 +13,11 @@ csc_cia_stne/slack.py,sha256=33_UNF7M529eIuWjmzSJFEZ4RmVNkFkuVxvxwsKY1tQ,8126
13
13
  csc_cia_stne/stne_admin.py,sha256=vnGSEzcmqWE42vg71oEuoRg6ENaGsZsXFOjxduSH4KU,23561
14
14
  csc_cia_stne/web.py,sha256=_pc6BzPy2x0RvqtZsByjtKcSuUqlVTevfmmmKbVWLhA,15417
15
15
  csc_cia_stne/utilitarios/__init__.py,sha256=0FrfH9XklutPS4QlbGjNYPulNfO2LFQoFXRnJQm-pKE,283
16
- csc_cia_stne/utilitarios/functions/__init__.py,sha256=rdEp4-g0hGu6QF0q6t9VtyedCpYqvQLf7xXlYKxnrrs,422
16
+ csc_cia_stne/utilitarios/functions/__init__.py,sha256=nUcjSI23FxfX18AQ8Q_Gimyxme35JTyfCYNcIypPfNU,527
17
17
  csc_cia_stne/utilitarios/functions/func_b64.py,sha256=XGU34BIQQXWXBS0yM2B4A2wDlcrMl1unIJXjq4lpLnk,1254
18
18
  csc_cia_stne/utilitarios/functions/func_converters.py,sha256=EY1zvlBaRX7G1MceVSiRXwwKDQDZwUO9iECBL0fe5iU,481
19
19
  csc_cia_stne/utilitarios/functions/func_get_secret.py,sha256=khTtUTE-acdA9lIM8l7weejDSqoTYlf59ypBdC_F_lw,2150
20
+ csc_cia_stne/utilitarios/functions/func_rdp.py,sha256=6nUKxa_sHqpz1kvdnOEyKkVopZY3QEByqZ6Sfw64gOs,2791
20
21
  csc_cia_stne/utilitarios/functions/func_recriar_pastas.py,sha256=4whZpB3aJQaCPJ3osMAQpKrzEhqYtJbljGWlx_OvKIM,826
21
22
  csc_cia_stne/utilitarios/functions/func_settings.py,sha256=XwlfqdcfocXQ8kTsDKZ6GsAtpzr0_u44AOTIMtdem7U,2059
22
23
  csc_cia_stne/utilitarios/functions/func_titulo.py,sha256=bH4tYxovTARF-g2kWUK_GIzzXt8egbVdp6mWD6fc_3I,5345
@@ -25,8 +26,8 @@ csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=PBo-AV2bjR__
25
26
  csc_cia_stne/utilitarios/validations/ServiceNowValidator.py,sha256=yleKUIo1ZfyloP9fDPNjv3JJXdLcocT81WIgRSYmqEA,14423
26
27
  csc_cia_stne/utilitarios/validations/__init__.py,sha256=O_qyEU2ji3u6LHUXZCXvUFsMpoMWL625qqHTXyXivTA,106
27
28
  csc_cia_stne/utilitarios/validations/web_validator.py,sha256=HYKYSpDv1RvRjZIuwTPt-AbEz-9392MxM_O329iYuSA,5722
28
- csc_cia_stne-0.0.58.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
29
- csc_cia_stne-0.0.58.dist-info/METADATA,sha256=8l3yCTUBCoqJcXuvwv5ioCz_13UvJLiibQVTHSOMYSw,1265
30
- csc_cia_stne-0.0.58.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
31
- csc_cia_stne-0.0.58.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
32
- csc_cia_stne-0.0.58.dist-info/RECORD,,
29
+ csc_cia_stne-0.0.60.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
30
+ csc_cia_stne-0.0.60.dist-info/METADATA,sha256=sG1SMPQd88mTGRsZsYElFnIPoJ6wiwpWM9aOgw-9534,1287
31
+ csc_cia_stne-0.0.60.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
32
+ csc_cia_stne-0.0.60.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
33
+ csc_cia_stne-0.0.60.dist-info/RECORD,,