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.
- worker_automate_hub/api/ahead_service.py +30 -21
 - worker_automate_hub/api/client.py +3 -0
 - worker_automate_hub/tasks/jobs/devolucao_prazo_a_faturar.py +1488 -0
 - worker_automate_hub/tasks/task_definitions.py +2 -0
 - worker_automate_hub/tasks/task_executor.py +1 -1
 - worker_automate_hub/utils/util.py +545 -8
 - {worker_automate_hub-0.5.37.dist-info → worker_automate_hub-0.5.39.dist-info}/METADATA +1 -1
 - {worker_automate_hub-0.5.37.dist-info → worker_automate_hub-0.5.39.dist-info}/RECORD +10 -9
 - {worker_automate_hub-0.5.37.dist-info → worker_automate_hub-0.5.39.dist-info}/WHEEL +0 -0
 - {worker_automate_hub-0.5.37.dist-info → worker_automate_hub-0.5.39.dist-info}/entry_points.txt +0 -0
 
| 
         @@ -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 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 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"
         
     |