worker-automate-hub 0.5.593__py3-none-any.whl → 0.5.596__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.

Potentially problematic release.


This version of worker-automate-hub might be problematic. Click here for more details.

@@ -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} !"
@@ -384,17 +384,30 @@ async def integracao_contabil_generica(
384
384
  )
385
385
 
386
386
  botao_integrar.click_input()
387
-
387
+ assets_int_cont = "assets\\integracao_contabil\\"
388
+ err_dict = {
389
+ assets_int_cont + "erro_duplicidade.png": "Erro de Duplicidade localizado enquanto finalizava a integração.",
390
+ assets_int_cont + "conta_indefinida_error.png": "Conta contábil indefinida no sistema.",
391
+ assets_int_cont + "lote_sem_complemento_error.png": "Lote encontrado sem complemento obrigatório.",
392
+ }
388
393
  # Aguardar finalizar
389
394
  while True:
390
395
  try:
396
+ for img_path, mensagem in err_dict.items():
397
+ err = pyautogui.locateOnScreen(img_path, confidence=0.86)
398
+ if err:
399
+ console.print(f"[red]Erro encontrado:[/red] {mensagem}")
400
+ return RpaRetornoProcessoDTO(
401
+ sucesso=False,
402
+ retorno=mensagem,
403
+ status=RpaHistoricoStatusEnum.Falha,
404
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)],
405
+ )
391
406
  # Conecta à janela do tipo MsgBox
392
- time.sleep(1)
407
+ await worker_sleep(1)
393
408
  app = Application(backend="win32").connect(class_name="TMsgBox")
394
409
  msgbox = app.window(class_name="TMsgBox", title_re="Inform.*")
395
-
396
410
  msgbox.set_focus()
397
-
398
411
  # Procura pelo botão com texto '&Ok'
399
412
  botao_ok = msgbox.child_window(class_name="TBitBtn", title="&Ok")
400
413
  if botao_ok.exists() and botao_ok.is_visible():
@@ -402,24 +415,7 @@ async def integracao_contabil_generica(
402
415
  console.print("Botão '&Ok' clicado com sucesso.")
403
416
  break
404
417
  except ElementNotFoundError:
405
- console.print("Janela MsgBox não encontrada ainda. Verificando existencia de erro de duplicidade...")
406
- try:
407
- duplicidade_err_img = "assets\\integracao_contabil\\erro_duplicidade.png"
408
- duplicidade_err = pyautogui.locateOnScreen(
409
- duplicidade_err_img, confidence=0.86
410
- )
411
- console.print("Verificando imagem...")
412
- if duplicidade_err:
413
- console.print("Erro de Duplicidade localizado.")
414
- return RpaRetornoProcessoDTO(
415
- sucesso=False,
416
- retorno=f"Erro de Duplicidade localizado enquanto finalizava a integração.",
417
- status=RpaHistoricoStatusEnum.Falha,
418
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)],
419
- )
420
- console.print("Erro de Duplicidade não localizado.")
421
- except Exception as err:
422
- print(f"Sem erro de Duplicidade.\nDetalhe: {err}")
418
+ console.print("Janela MsgBox não encontrada ainda.")
423
419
  except Exception as e:
424
420
  print(f"Erro ao tentar clicar no botão: {e}")
425
421
 
@@ -3278,7 +3278,7 @@ async def check_nota_importada(xml_nota: str) -> RpaRetornoProcessoDTO:
3278
3278
  from worker_automate_hub.api.client import get_status_nf_emsys
3279
3279
 
3280
3280
  try:
3281
- max_attempts = 60
3281
+ max_attempts = 100
3282
3282
  i = 0
3283
3283
 
3284
3284
  while i < max_attempts:
@@ -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.596
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
@@ -74,7 +74,7 @@ worker_automate_hub/tasks/jobs/fidc_remessa_cobranca_cnab240.py,sha256=XCbIZG1y7
74
74
  worker_automate_hub/tasks/jobs/fidc_retorno_cobranca.py,sha256=6BtgiHZ8gLiKpOHwF3Tba4oVFZDUbUUwaHw7WK_5V2I,11879
75
75
  worker_automate_hub/tasks/jobs/geracao_aprovacao_pedidos.py,sha256=QzK2aG5d9pmFbb8cTaNm3LWf5NMkmCvBkgo70gcLu0c,14781
76
76
  worker_automate_hub/tasks/jobs/integracao_contabil.py,sha256=psoIU0tjtTJq2W8aGXjXrfkAOYlIpUtHZyNolI7dp-0,16263
77
- worker_automate_hub/tasks/jobs/integracao_contabil_generica.py,sha256=uyiktW67IL-r1jl_LtGk2Us0gz6rB3uW6u3MutF2NHU,18098
77
+ worker_automate_hub/tasks/jobs/integracao_contabil_generica.py,sha256=mQo6d_X5gC5t5gnt4lyQPN7J30u8e4f81dWRjzH5Mk8,18060
78
78
  worker_automate_hub/tasks/jobs/lancamento_pis_cofins.py,sha256=9BePVw8AP42mRKRiWqZHxIah9rGOqoBXs_Vo-OQBioM,35679
79
79
  worker_automate_hub/tasks/jobs/login_emsys.py,sha256=dO9S027qRTtjOfytF6IWO-m6hDld8kZqOVAsn91l1YA,5684
80
80
  worker_automate_hub/tasks/jobs/login_emsys_versao_especifica.py,sha256=_6CFh79eaW9KdPGR6FMV01ASPjJzNzzBK1MvC_uiSOo,5625
@@ -90,10 +90,10 @@ worker_automate_hub/utils/get_creds_gworkspace.py,sha256=ZJ0IIEjM4IXIV9rwfbOZ1V1
90
90
  worker_automate_hub/utils/logger.py,sha256=FYV9fg0_RAYJF_ZOCJEbqQAiCXlXk2gMpvUU1rzT_xs,671
91
91
  worker_automate_hub/utils/toast.py,sha256=xPHc5r5uOxB_cZlCzm13Kt2qSKLLFZALncU6Qg3Ft68,1162
92
92
  worker_automate_hub/utils/updater.py,sha256=en2FCGhI8aZ-JNP3LQm64NJDc4awCNW7UhbVlwDl49Y,7972
93
- worker_automate_hub/utils/util.py,sha256=mFsEBbrIJBP_jyGj1bRbQjZuPH8LmXqgXQOuVZmx8aA,198280
93
+ worker_automate_hub/utils/util.py,sha256=_pgZOFWgXoov6WPbqyRTDVXJCRFfucYB3gb9swzU7bo,198281
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.596.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
97
+ worker_automate_hub-0.5.596.dist-info/METADATA,sha256=z3BxWiHHeJw3oimu337GSQNNbc7bbMiq2-Gh82ZE6ts,3012
98
+ worker_automate_hub-0.5.596.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
99
+ worker_automate_hub-0.5.596.dist-info/RECORD,,