worker-automate-hub 0.5.593__py3-none-any.whl → 0.5.594__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.
@@ -591,43 +591,45 @@ async def send_file(
591
591
  file_extension: str = "jpg",
592
592
  ) -> None:
593
593
  """
594
- Função assíncrona para enviar um arquivo de imagem/text para uma API.
594
+ Função assíncrona para enviar um arquivo para uma API.
595
595
 
596
596
  Args:
597
597
  uuidRelacao (str): UUID da relação associada ao arquivo.
598
- desArquivo (str): Descrição do arquivo.
599
- tipo (str): Tipo de arquivo.
598
+ desArquivo (str): Nome real do arquivo (com extensão).
599
+ tipo (str): Tipo de arquivo (ex: 'xls').
600
600
  file (bytes): Conteúdo binário do arquivo.
601
+ file_extension (str): Extensão do arquivo (sem o ponto), usada para definir o content-type.
601
602
  """
602
603
  try:
603
604
  # Carrega as configurações de ambiente
604
605
  env_config, _ = load_env_config()
605
606
 
607
+ # Define o content-type e o filename baseados na extensão
606
608
  if file_extension == "txt":
607
- filename = "text.txt"
608
609
  content_type = "text/plain"
609
610
  elif file_extension == "pdf":
610
- filename = "file.pdf"
611
611
  content_type = "application/pdf"
612
612
  elif file_extension == "jpg":
613
- filename = "file.jpg"
614
613
  content_type = "image/jpeg"
615
614
  elif file_extension == "001":
616
- filename = desArquivo
617
615
  content_type = "text/plain"
618
- elif file_extension =="xls":
619
- filename = "file.xls"
616
+ elif file_extension == "xls":
620
617
  content_type = "application/vnd.ms-excel"
618
+ elif file_extension == "xlsx":
619
+ content_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
620
+ else:
621
+ raise ValueError(f"Extensão de arquivo não suportada: {file_extension}")
621
622
 
622
623
  # Criação do corpo da requisição multipart
623
624
  body = aiohttp.FormData()
624
625
  body.add_field("uuidRelacao", uuidRelacao)
625
626
  body.add_field("desArquivo", desArquivo)
626
627
  body.add_field("tipo", tipo)
627
- body.add_field("file", file, filename=filename, content_type=content_type)
628
- # body.add_field('file', file, filename="file.jpg", content_type="image/jpeg")
628
+ body.add_field("file", file, filename=desArquivo, content_type=content_type)
629
629
 
630
- headers_basic = {"Authorization": f"Basic {env_config['API_AUTHORIZATION']}"}
630
+ headers_basic = {
631
+ "Authorization": f"Basic {env_config['API_AUTHORIZATION']}"
632
+ }
631
633
 
632
634
  # Enviando requisição para a API
633
635
  async with ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
@@ -636,8 +638,11 @@ async def send_file(
636
638
  data=body,
637
639
  headers=headers_basic,
638
640
  ) as response:
639
- response.raise_for_status() # Levanta exceção se o status não for 2xx
640
- log_msg = f"\nSucesso ao enviar arquivo: {uuidRelacao}.\n"
641
+ if response.status != 200:
642
+ content = await response.text()
643
+ raise Exception(f"Erro {response.status} - Resposta da API: {content}")
644
+
645
+ log_msg = f"\n✅ Sucesso ao enviar arquivo: {uuidRelacao}\n"
641
646
  console.print(log_msg, style="bold green")
642
647
  logger.info(log_msg)
643
648
 
@@ -5,6 +5,7 @@ import os
5
5
  import re
6
6
  import io
7
7
  import json
8
+ from pathlib import Path
8
9
  import uuid
9
10
  import pandas as pd
10
11
  import pyautogui
@@ -18,7 +19,6 @@ from pywinauto.mouse import double_click
18
19
  import win32clipboard
19
20
  from pywinauto_recorder.player import set_combobox
20
21
  from rich.console import Console
21
- from worker_automate_hub.api.ahead_service import save_xml_to_downloads
22
22
  from worker_automate_hub.api.datalake_service import send_file_to_datalake
23
23
  from worker_automate_hub.api.client import (
24
24
  get_config_by_name,
@@ -327,12 +327,8 @@ async def extracao_fechamento_contabil(
327
327
  data_final_arquivo = periodo_final.replace("/", "")
328
328
 
329
329
  # Caminho completo para Downloads
330
- caminho_downloads = os.path.join(os.environ["USERPROFILE"], "Downloads")
331
- nome_arquivo = os.path.join(
332
- caminho_downloads,
333
- f"balancete_{data_inicial_arquivo}_{data_final_arquivo}_{date_now}.xls"
334
- )
335
-
330
+ nome_arquivo = f"C:\\Users\\{getpass.getuser()}\\Downloads\\balancete_{data_inicial_arquivo}_{data_final_arquivo}_{date_now}.XLS"
331
+
336
332
  console.print(f"Salvar arquivo: {nome_arquivo}")
337
333
 
338
334
  # Inserir nome do arquivo
@@ -347,8 +343,9 @@ async def extracao_fechamento_contabil(
347
343
  botao_salvar = main_window.child_window(class_name="Button", found_index=0)
348
344
  botao_salvar.click_input()
349
345
 
350
- await worker_sleep(3)
351
-
346
+ await worker_sleep(2)
347
+
348
+
352
349
  ##### Janela Print #####
353
350
 
354
351
  app = Application(backend="win32").connect(title="Print")
@@ -374,18 +371,22 @@ async def extracao_fechamento_contabil(
374
371
  await worker_sleep(5)
375
372
 
376
373
  username = getpass.getuser()
377
- # Nome original (com .XLS maiúsculo)
378
- caminho_arquivo = f"C:\\Users\\{username}\\Downloads\\{nome_arquivo}.XLS"
379
-
380
- # Novo nome com extensão minúscula
381
- caminho_ajustado = caminho_arquivo.rsplit(".", 1)[0] + ".xls"
382
-
383
- # Renomeia o arquivo
384
- os.rename(caminho_arquivo, caminho_ajustado)
385
374
 
386
375
  await worker_sleep(3)
387
376
 
388
377
  console.print("Criar arquivo JSON")
378
+
379
+ arquivo_path = Path(nome_arquivo)
380
+ # Altera a extensão para .XLS maiúsculo (caso o EMSys exporte assim)
381
+ caminho_arquivo = arquivo_path.with_suffix('.XLS')
382
+ # Altera a extensão final para .xls minúsculo
383
+ caminho_ajustado = caminho_arquivo.with_suffix('.xls')
384
+ nome_com_extensao = caminho_ajustado.name
385
+ print(nome_com_extensao)
386
+ # Renomeia o arquivo
387
+ os.rename(caminho_arquivo, caminho_ajustado)
388
+
389
+ console.print(f"Arquivo renomeado para: {caminho_ajustado}")
389
390
  # Caminho do arquivo
390
391
  arquivo = caminho_ajustado
391
392
 
@@ -424,7 +425,8 @@ async def extracao_fechamento_contabil(
424
425
  # Salva o JSON
425
426
 
426
427
  # Caminho completo do arquivo
427
- full_path = f"C:\\Users\\{username}\\Downloads\\{nome_arquivo}.json"
428
+ nome_sem_extensao = caminho_ajustado.stem
429
+ full_path = f"C:\\Users\\{username}\\Downloads\\{nome_sem_extensao}.json"
428
430
  filename = os.path.basename(full_path)
429
431
  with open(full_path, "w", encoding="utf-8") as f:
430
432
  json.dump(dados_json, f, ensure_ascii=False, indent=2)
@@ -462,12 +464,14 @@ async def extracao_fechamento_contabil(
462
464
  try:
463
465
  await send_file(
464
466
  historico_id,
465
- caminho_ajustado,
467
+ nome_com_extensao,
466
468
  "xls",
467
469
  file_bytes,
468
470
  file_extension="xls",
469
471
  )
472
+ console.print("Removendo arquivo XLS da pasta downloads")
470
473
  os.remove(f"{caminho_ajustado}")
474
+ console.print("Removendo arquivo JSON da pasta downloads")
471
475
  os.remove(full_path)
472
476
  except Exception as e:
473
477
  result = f"Arquivo Balancete contábil gerado com sucesso, porém gerou erro ao realizar o envio para o backoffice {e} - Arquivo ainda salvo na dispositivo utilizado no diretório {caminho_arquivo} !"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: worker-automate-hub
3
- Version: 0.5.593
3
+ Version: 0.5.594
4
4
  Summary: Worker Automate HUB é uma aplicação para automatizar rotinas de RPA nos ambientes Argenta.
5
5
  Author: Joel Paim
6
6
  Requires-Python: >=3.12,<4.0
@@ -1,7 +1,7 @@
1
1
  worker_automate_hub/__init__.py,sha256=LV28uQvBfpPIqudGIMJmVB8E941MjXHcu8DMoX5n8AM,25
2
2
  worker_automate_hub/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  worker_automate_hub/api/ahead_service.py,sha256=QbNrZf9q7fS0s-S5fZVytqC7dINi9u2f6aB6SDrGVVA,2231
4
- worker_automate_hub/api/client.py,sha256=HpKljeRl3qdXQCrGHrG-as6_t2adNv__BzcjOazhg08,25155
4
+ worker_automate_hub/api/client.py,sha256=LVnM1ymiU_RpIbIpqUJwIM0jCWotkkxWMUi2O2QWwno,25443
5
5
  worker_automate_hub/api/datalake_service.py,sha256=qw_N_OOgDKDuPbI-fdYkWWTlT4CUtFTl0VVlZ0fLM-M,3001
6
6
  worker_automate_hub/api/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  worker_automate_hub/api/helpers/api_helpers.py,sha256=SkheO2fXexeh-a4shr8Qzsz_kZhuSG0DJ7kbODctRbM,3696
@@ -66,7 +66,7 @@ worker_automate_hub/tasks/jobs/entrada_de_notas_505.py,sha256=xXeNipdXTSll8yAtAm
66
66
  worker_automate_hub/tasks/jobs/entrada_de_notas_7139.py,sha256=aSgHterguK9XGtq0Bf__YlXo5pewb9P-BRZTLnrH1D8,29020
67
67
  worker_automate_hub/tasks/jobs/entrada_de_notas_9.py,sha256=VJ-2g7tuqbAICOarJpAhljjJJ5wbb5hphTboBWoxj7M,64639
68
68
  worker_automate_hub/tasks/jobs/exemplo_processo.py,sha256=nV0iLoip2FH2-FhLmhX3nPqsfl_MPufZ3E5Q5krJvdc,3544
69
- worker_automate_hub/tasks/jobs/extracao_fechamento_contabil.py,sha256=st49Bxz32pddb0OM9j2XCZq2A3ivhb0kcNnQ6saD6qk,18880
69
+ worker_automate_hub/tasks/jobs/extracao_fechamento_contabil.py,sha256=rnzU8TVWYDI1AC7k9xv40_Y16j574b4vOCWdwnuqcA0,19196
70
70
  worker_automate_hub/tasks/jobs/fechar_conexao_rdp.py,sha256=UWAKCS2dbfgDlSQOBdjmVJXfD1MMuUrOi3weDgB0CAc,5718
71
71
  worker_automate_hub/tasks/jobs/fidc_exportacao_docs_portal_b2b.py,sha256=SOs2mORBJqHs089ApbLaPJVRXM7wWhf0e99URXqPlpQ,15020
72
72
  worker_automate_hub/tasks/jobs/fidc_gerar_nosso_numero.py,sha256=zu92tRCvKPK0U6IGGF28ST-kERohJcNbys-DWk0tIco,12555
@@ -93,7 +93,7 @@ worker_automate_hub/utils/updater.py,sha256=en2FCGhI8aZ-JNP3LQm64NJDc4awCNW7UhbV
93
93
  worker_automate_hub/utils/util.py,sha256=mFsEBbrIJBP_jyGj1bRbQjZuPH8LmXqgXQOuVZmx8aA,198280
94
94
  worker_automate_hub/utils/utils_nfe_entrada.py,sha256=wmnpuOesmPSryZszmapa37b9YNC0E2MkeDYnbwr-0rU,33315
95
95
  worker_automate_hub/worker.py,sha256=axdrr1xLTjWEyWfcyH3OCSpPTsyzck_fL_0u1DBLjvw,6525
96
- worker_automate_hub-0.5.593.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
97
- worker_automate_hub-0.5.593.dist-info/METADATA,sha256=8vKtiP28OVLjx1UrH5SpxshnbubWHt9LvWHX5fClJ1E,3012
98
- worker_automate_hub-0.5.593.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
99
- worker_automate_hub-0.5.593.dist-info/RECORD,,
96
+ worker_automate_hub-0.5.594.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
97
+ worker_automate_hub-0.5.594.dist-info/METADATA,sha256=DOf8GvqpYFXtcWw1stAe6y_MrrWT_sQipKnoXlkQ7Rg,3012
98
+ worker_automate_hub-0.5.594.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
99
+ worker_automate_hub-0.5.594.dist-info/RECORD,,