worker-automate-hub 0.5.37__py3-none-any.whl → 0.5.39__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.
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import os
2
3
  from pathlib import Path
3
4
  import getpass
@@ -5,6 +6,7 @@ import aiohttp
5
6
  from worker_automate_hub.config.settings import load_env_config
6
7
  from worker_automate_hub.utils.logger import logger
7
8
 
9
+
8
10
  async def get_xml(chave_acesso: str):
9
11
  env_config, _ = load_env_config()
10
12
  try:
@@ -31,26 +33,33 @@ async def get_xml(chave_acesso: str):
31
33
  logger.error(err_msg)
32
34
  return None
33
35
 
36
+
34
37
  async def save_xml_to_downloads(chave_acesso: str):
35
- xml_content = await get_xml(chave_acesso)
36
- if xml_content:
37
- try:
38
- downloads_path = Path.home() / "Downloads"
39
- downloads_path.mkdir(parents=True, exist_ok=True)
40
-
41
- file_name = f"{chave_acesso}.xml"
42
- file_path = downloads_path / file_name
43
-
44
- with open(file_path, 'w', encoding='utf-8') as f:
45
- f.write(xml_content)
46
-
47
- logger.info(f"XML salvo em {file_path}")
48
- return True
49
- except Exception as e:
50
- err_msg = f"Erro ao salvar o XML: {e}"
38
+ MAX_RETRIES = 3
39
+
40
+ for attempt in range(1, MAX_RETRIES + 1):
41
+ xml_content = await get_xml(chave_acesso)
42
+ if xml_content:
43
+ try:
44
+ downloads_path = Path.home() / "Downloads"
45
+ downloads_path.mkdir(parents=True, exist_ok=True)
46
+
47
+ file_name = f"{chave_acesso}.xml"
48
+ file_path = downloads_path / file_name
49
+
50
+ with open(file_path, "w", encoding="utf-8") as f:
51
+ f.write(xml_content)
52
+
53
+ logger.info(f"XML salvo em {file_path}")
54
+ return True
55
+ except Exception as e:
56
+ err_msg = f"Erro ao salvar o XML: {e}"
57
+ logger.error(err_msg)
58
+ else:
59
+ err_msg = "Não foi possível obter o XML."
51
60
  logger.error(err_msg)
52
- return False
53
- else:
54
- err_msg = "Não foi possível obter o XML."
55
- logger.error(err_msg)
56
- return False
61
+
62
+ if attempt < MAX_RETRIES:
63
+ await asyncio.sleep(2)
64
+
65
+ return False
@@ -460,6 +460,9 @@ async def send_file(uuidRelacao: str, desArquivo: str, tipo: str, file: bytes, f
460
460
  if file_extension == "txt":
461
461
  filename = "text.txt"
462
462
  content_type = "text/plain"
463
+ elif file_extension == "pdf":
464
+ filename = "file.pdf"
465
+ content_type = "application/pdf"
463
466
  else:
464
467
  filename = "file.jpg"
465
468
  content_type = "image/jpeg"