
    8=Khu                        d dl Zd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZ d dlmZ d dlmZmZ d dlmZ d dlZd dlmZ dZdZg d	Zd
gZdCdZd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%	 d Z&d Z'd Z(d Z)	 d Z*	 d Z+	 d Z,	 d  Z-	 d! Z.d" Z/	 d# Z0d$ Z1	 d% Z2d& Z3d' Z4d( Z5	 d) Z6d* Z7d+ Z8d, Z9d- Z:d. Z;dDd1Z<d2 Z=d3 Z>d4 Z?d5 Z@d6 ZAd7 ZBd8 ZCd9 ZDd: ZEd; ZFd< ZGd= ZHd> ZId? ZJd@ ZKdA ZLdB ZMdS )E    N)async_playwrightexpect)defaultdict)datetime	timedelta)stealth)platformi  z3https://dev.carteraplus.com/REST/Controller.php?opt)obtenerDocumentoPoliza obtenerDocumentoRecibosYFacturasexportarReportePagadasexportarReportePagadasV2exportarReportePorRenovarexportarReportePorPagarexportarReportePorPagarV2exportarReporteCancelacionesexportarReporteRenovacionesexportarReportesSiniestrosVPobtenerDatosClienteverificaLoginSesionnotificarAClienteReciboFc                   K   t                                                       d {V }| dk    rdnd} d} g d}g d}g d}i }	 d|vr'|j                            | g dd	g
           d {V }n6t	          d           |j                            || g dd	g           d {V }d| d}	|du r^t
          j                            |	          r |                    |	ddg           d {V }
n=|                    ddg           d {V }
n|                    ddg           d {V }
|
j	                            ddd           d {V  |

                                 d {V }|||fS )NsiTF)con_65d0b5a0631ebcon_65d0b5a75db92con_65d0b5ad5002ccon_65e0aea360911)con_66391395e9ab2con_6639137b96cd0con_6639124fe856bcon_663911f25f1bfcon_663911ba645e0con_6639119d7c698)con_663e74560850e2con_663e744c65c792con_663e7440bbc9e2con_663e73cb6459d2con_663e72c70ddb42con_663e7298308952con_663e728422f802con_663e747ea2c03server)--disable-extensions%--disable-background-timer-throttling(--disable-backgrounding-occluded-windows --disable-renderer-backgrounding--no-sandboxz--disable-infobars)headlessargsignore_default_argszS ========================= PROXY INICIADO PARA ELITE !!! ========================= )r,   r-   r.   r/   r0   z--use-fake-ui-for-media-stream)proxyr1   r2   r3   ../sessions/.jsongeolocationstorage_stateaccept_downloadspermissionsr:   r;   )screenshots	snapshotssources)r   startchromiumlaunchprintospathexistsnew_contexttracingnew_page)ocultarNavegadorsessionwhatsappUsepramirosdeltoroeliteBrokersr4   browsersession_filecontextpages               ?/var/www/wsoft.com.mx/carteraplus-automatizador/python/utils.pyinicializarPlaywrightrV   "   sx     $$&&&&&&&&!-55TT5 cbb' M  M  M' C  C  C,
%  UJ%%   00 & 
 
 
 
 
 
 
 
GG 

_```J%%   00 &        G /..., E	w~~l## ^))W[ivhw)yyyyyyyygg))4]O)]]]]]]]]gg))4]O)]]]]]]]]g%5%PPPPPPPPP!!	!	!	!	!	!	!$ 
GT	    c                   K   d| d}t           j                            |          r |                     |ddg           d {V }n|                     ddg           d {V }|                                 d {V }|S )Nr5   r6   Tr7   r8   r<   )rD   rE   rF   rG   rI   )rQ   rK   rR   rS   page2s        rU   abrirPestanaPlaywrightrZ   l   s      ...., W^^L!! \''lUYgtfu'wwwwwwwwGG''=/'[[[[[[[[G  ""
"
"
"
"
"
"% 
,rW   c                 r   K   |                                  d {V  |                                  d {V  d S N)closestop)rM   rQ   s     rU   cerrarPlaywrightr_   y   sC      	.........rW   c                    K   g }g }| D ]K}|d         t           v r|                    |           '|d         t          v r|                    |           L||fS )Nfuncion)diccionarioNavegadorappenddiccionarioWhatsapp)	subtareassubtareasNavegadorsubtareasWhatsappitems       rU   organizaSubtareasri   ~   sy       % %dI...%%%%	i/	/	/t$$$	.	..rW   c                  (   K   t          d           d S )NERROR)rC    rW   rU   salidaErrorrm      s      .....rW   c                    K   d| v rd| d<   dt            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Ncredencialesr   https://dev.carteraplus.com:	/reenviarjson)	PUERTO_DEL_NODOaiohttpClientSessionpostrs   asyncioget_event_looprun_until_completeenviar_jsondataurlhttp	respuestarespuesta_jsonloop	resultados          rU   enviarMensajer      sE     tDAAAA#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))s5   B3B*B3
B	B3B	B33
B= B=c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz7=notificacionesapps/avisoNotificacionesGeneralesSistemarr   	
URL_SERVERru   rv   rw   rs   rx   ry   rz   r{   r|   s          rU   #avisoNotificacionesGeneralesSistemar      s.     NNN#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))5   B)B B)
B	B)B	B))
B36B3c                   K   d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t                                          }|                    t                                }d S )NzUhttps://mercedes.wsoft.com.mx/WSDL/checador_aseguradoras.php?opt=imprimirReciboAfirmerr   ru   rv   rw   rs   rx   ry   rz   r{   r|   s          rU   obtenerPolizaAfirmeSWr      s%     `#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))4   B!A=B!=
B	B!
B	B!!
B+.B+c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz=agente/obtenerPolizaGuardadarr   r   r|   s          rU   obtenerPolizaGuardadar      s.     444#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz=agente/guardarPolizarr   r   r|   s          rU   guardarPolizar      s.     ,,,#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz$=administrador/actualizarNoReciboGNPrr   r   r|   s          rU   actualizarNoReciboGNPr      .     ;;;#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                     d| v rd| d<   dt            d}t          j        ||           }|j        dk    r$t	          d|                                           d S t	          d|j                    d S )	Nro   r   rp   rq   rr      zrespuesta correctaz Error al realizar la solicitud: )rt   requestsrw   status_coderC   rs   r}   r~   r   s      rU   enviarMensajeDirector      s    tDAAAA#mCd+++)c!!	
	 0 011111	
DY-B
D
DEEEEErW   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }|S )Nz =administrador/errorInicioSesionrr   r   r|   s          rU   notificarErrorSesionr      s0     777#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)	r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz*=administrador/actualizarWhatsappConectadorr   r   r|   s          rU   actualizarWhatsappConectador      .     AAA#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }|S )Nz)=administrador/crearNuevaConexionWhatsapprr   r   r|   s          rU   crearNuevaConexionWhatsappr      0     @@@#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)	r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz5=administrador/dispersarConexionesYEliminarDuplicadosrr   r   r|   s          rU   &dispersarConexionesYEliminarDuplicadosr      s.     LLL#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }|S )Nz)=administrador/obtenerInformacionReciboBDrr   r   r|   s          rU   obtenerInformacionReciboBDr     r   r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz#=administrador/actualizarFechaLoginrr   r   r|   s          rU   actualizarFechaLoginr     .     :::#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz'=administrador/actualizarConteoUsoTarearr   r   r|   s          rU   actualizarConteoUsoTarear   #  .     >>>#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz=administrador/registrarRecibosrr   r   r|   s          rU   registrarRecibosr   1  s.     666#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz'=administrador/actualizarStatusSubtarearr   r   r|   s          rU   actualizarStatusSubtarear   ?  r   r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz/=administrador/actualizarStatusNavegadorAbiertorr   r   r|   s          rU    actualizarStatusNavegadorAbiertor   M  s.     FFF#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz.=administrador/actualizarStatusWhatsappAbiertorr   r   r|   s          rU   actualizarStatusWhatsappAbiertor   W  s.     EEE#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S Nz$=administrador/actualizarStatusTarearr   r   r|   s          rU   actualizarStatusTarear   e  r   r   c                 F    t            d}t          j        ||           }d S r   )r   r   rw   r   s      rU   actualizarStatusTareaDirector   o  s(    ;;;#mCd+++)))rW   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz#=administrador/obtenerDatosConexionrr   r   r|   s          rU   obtenerDatosConexionr   x  r   r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz-=administrador/obtenerCredencialesPorConexionrr   r   r|   s          rU   obtenerCredencialesPorConexionr     s.     DDD#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz+=administrador/obtenerConexionPorIdWhatsapprr   r   r|   s          rU   obtenerConexionPorIdWhatsappr     s.     BBB#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)))r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz*=administrador/registraReciboSinExistenciarr   r   r|   s          rU   registraReciboSinExistenciar     r   r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }d S )Nz*=administrador/registrarDatosAutogeneradosrr   r   r|   s          rU   registrarDatosAutogeneradosr     r   r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }|S )Nz,=agente/obtenerWhatsappConectadosPorIdAccesorr   r   r|   s          rU   $obtenerWhatsappConectadosPorIdAccesor     s0     CCC#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)	r   c                   K   t            d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t
                                          }|                    t                                }|S )Nz*=administrador/enviarReporteMasivoWhatsapprr   r   r|   s          rU   enviarReporteMasivoWhatsappr     s0     AAA#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)	r   c                   K   d}t          j                    4 d {V }|                    ||           4 d {V }|                                 d {V }|cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   	 d d d           d {V  n# 1 d {V swxY w Y   t                                          }|                    t                                }|S )NzVhttps://vpsiniestros.wsoft.com.mx/REST/Controller.php?opt=obtenerClavesAgentesVigentesrr   r   r|   s          rU   obtenerClavesAgentesVigentesr     s'     a#"$$       yy4y((       I&^^--------n                                                                 
 
			!	!$%%kmm44)	r   c                 
   K   dS )NFrl   )r}   s    rU   	leerExcelr     s      	rW   c                 T   | d         dk    r
| d         }|S | d         dk    r@| d         D ]*}|d         dk    r|d         }|d         d	k    r|d         }+| d         }|||fS | d         d
k    rU| d         D ]>}|d         dk    r|d         }|d         dk    r|d         }|d         d	k    r|d         }?| d         }||||fS | d         dk    r@| d         D ]*}|d         dk    r|d         }|d         d	k    r|d         }+| d         }|||fS | d         dk    r@| d         D ]*}|d         dk    r|d         }|d         d	k    r|d         }+| d         }|||fS | d         dk    r@| d         D ]*}|d         dk    r|d         }|d         d	k    r|d         }+| d         }|||fS d S )NidentificadorwhatsapprK   aryaformlabelUsuariovalueu   ContraseñaqualitasClaveCuentaaxagnphdirl   )r}   rK   rh   usuariopasswordclavecuentas          rU   generarVariablesr     sT   	/j((9oGN	/f$$V ! !	g)	#	#w-	g-	'	'=9oGHg%%	/j((V ! !	g'	!	!W	g(	"	"g	g-	'	'=9oG&(G++	/e##V ! !	g)	#	#w-	g-	'	'=9oGHg%%	/e##V ! !	g)	#	#w-	g-	'	'=9oGHg%%	/e##V ! !	g)	#	#w-	g-	'	'=9oGHg%% $#rW   Tautomatizadorc                   K   t          d          }|                    dd          }|                    dd          }||d}t          j        di |}t          j        di |}	d}
d| d	| }	 |                    | |
|
           |	                    |
                              |                                          	                    d           |rv	 t          j        |            n`# t          $ r t          d           Y dS t          $ r t          d           Y dS t          $ r}t          d|            Y d }~dS d }~ww xY w|S # t          $ r}t          d|            Y d }~dS d }~ww xY w)N/etc/aws_secret.conf
WIWI0_AKID 	WIWI0_SAKaws_access_key_idaws_secret_access_keys3wsoft1zsegurocotizas//)FilenameBucketKeyzpublic-read)ACLzEl archivo no se encuentraFz+No tienes permisos para eliminar el archivou   Ocurrió un error: z Error al subir el archivo a S3: r   )cargar_secretogetboto3clientresourceupload_filer   ObjectAclputrD   removeFileNotFoundErrorrC   PermissionError	Exception)routenombre_archivoeliminarArchivorutasecretos	ACCESS_ID
ACCESS_KEYAWS_S3_CREDS	s3_clients3_resourcebucket_name
object_keyes                rU   subirArchivoAS3r
    s     233( ||L"--)||K,,* #' , 22\22)44|44++777~77*
     {##**:66::<<@@]@SSS  

	%   *+++uu   ;<<<uu   'A''(((uuuuu 	   	
0Q
0
011155555s[   0A(E C. -E .EE 
E"E %	E.E E EE 
E7E22E7c                    i }t           j                            |           r]t          | d          5 }|D ]1}|                                                    d          \  }}|||<   2	 ddd           n# 1 swxY w Y   |S )z$Carga claves desde un archivo seguror=N)rD   rE   rF   openstripsplit)r   r  flinear   valors         rU   r   r   D  s    H	w~~d ($__ 	( ( (${{}}22377u"'(	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( Os   5A44A8;A8c                 F  K   t          d          }|                    dd          }|                    dd          }t          dk    rd}nd}||d}t          j        di |}d
}d|  }	| | }
	 |                    ||	|
           |
S # t          $ r}Y d }~dS d }~ww xY w)Nr   r   r   r   darwinzD/Users/wsoft/Documents/wsoft.com.mx/carteraplus-automatizador/files/6/var/www/wsoft.com.mx/carteraplus-automatizador/files/r   r   r   zsegurocotizas/automatizador/Fr   )r   r   r	   r   r   download_filer   )ruta_archivor   r  r  r  RUTA_FOLDERr  r   r  object_namedownload_pathr	  s               rU   descargarArchivoDeS3r  O  s      233( ll<,,)||K,,* XKKJK #' , |))L))"+=|==+ 2.22-[+}===	   55555s   2B 
B B c                     t          j                    }|t          | dz             z   }|t          |           z
  }|                    |          }|                    |          }|||                    |          fS )z DEFINIMOS FECHAS    )days)r   nowr   strftime)rangoformatohoyfecha_proximafecha_anteriors        rU   obtenerFechasEnRangor'  u  sz    #	
4444-..... ))'22-!**733.	W(=(=	==rW   c                 0   t          j        d          j        }d |                                D             }t	          d |d|  dgz   D                       }t          ||dz             }t          dd|z  z              d|  d}t          d	t          |          z             t          |           t          d	t          |          z  dz              |D ]'}t          |                    |d
z
                       (t          dd|z  z              dS )u  
  Imprime datos de manera elegante en la consola, ajustado al ancho de la terminal.

  Parámetros:
  - titulo (str): El título del bloque de datos.
  - datos (dict): Un diccionario donde cada clave es un dato a mostrar y cada valor es la descripción de ese dato.
  )P      c                 "    g | ]\  }}| d | S )z: rl   ).0r   r  s      rU   
<listcomp>zimprimir.<locals>.<listcomp>  s*    EEE|ue%""5""EEErW   c              3   4   K   | ]}t          |          V  d S r\   )len)r,  lines     rU   	<genexpr>zimprimir.<locals>.<genexpr>  s(      LLdD		LLLLLLrW   z| z |   
-r     N)	shutilget_terminal_sizecolumnsitemsmaxminrC   r/  ljust)titulodatosterminal_width	contenidomax_line_lengthanchotitulo_liner  s           rU   imprimirrD  ~  s,    +H55=.EEu{{}}EEE)LLi????:K.KLLLLL/
no1
2
2%sU{V+c+c+%&&& " "e	%++eai
 
 !!!!sU{rW   c                    K   |                                   d {V }t          dt          j        |                                                     d S )NzBASE ---- 
)
screenshotrC   base64	b64encodedecode)rT   screenshot_bytess     rU   generarCapturarK    sV      ??,,,,,,,,()9::AACCDDDDDrW   c                    K   t          | d          5 }t          j        ||d           d d d            d S # 1 swxY w Y   d S )Nwr5  )indent)r  rs   dump)r   arrayfiles      rU   crearArchivoJSONrR    s      D# %$IeT!$$$$% % % % % % % % % % % % % % % % % %s   8<<c                    K   t          t                    }| D ]G}d|v rA|d         dk    r5d|vrd|d<   ||d          d|d                                       |           H|S )Nid_conexionstatus	terminadoid_whatsappdescarga_)r   listrc   )listaarraySubtareasPorConexionrh   s      rU   obtenerArrayDeConexionesr]    s      )$// ] ]dh;!>!>	d	"	"(]4#6 N Nm9L N NOVVW[\\\	""rW   c                     K   t          j        d          } t          j        |           }|                    d          }|S )NzAmerica/Mexico_Cityz%Y-%m-%d %H:%M:%S)pytztimezoner   r   r!  )r`  r   formatted_dates      rU   getFecharb    s=      ]011(X#<< 344.	rW   c                    |                      dd          }|                    d          dk    sdS |                    d          \  }}}|                                r(|                                r|                                sdS t	          |          }t	          |          }t	          |          }d|cxk    rdk    rn nd|cxk    rdk    r	n n|d	k    sdS |d
d|dd|dS )N r   r4  r5  z
0000-00-00         r   04d02d)replacecountr  isdigitint)fechafecha_sin_espaciosdiamesyears        rU   formatearFechaGNPrs    s   }}S"--		!	!#	&	&!	+	+<%++C00.#sD
++-- CKKMM dllnn <C#C#	T$
s....b.....Q#^^^^^^^^^q<	*	*	*s	*	*	*	*	*	**rW   c                     |                                  \  }}|                    dd                              dd          }|dk    rdnd}||fS )N$r   ,MXNUSDPESOS)r  rj  )cadenamonto_con_simbolomonedamonto_sin_caracterestipo_monedas        rU   formateaMontoYMonedaGNPr    s[    $llnnV +223;;CCCLL  5g+	{	**rW   c                 l    i }| D ].}|d         }||vrg ||<   ||                              |           /|S )Nr   )rc   )rP  agrupados_por_identificadorrecibor   s       rU   agrupaReportePorIdentificadorr    s^     " 	> 	>f?+M 77735!-0  .55f====	$$rW   c                 d   g d}g d}g d}g d}i }|                                  D ]\  }}t          j        |          }	|dk    r	|	|         }	n,|dk    r	|	|         }	n|dk    r	|	|         }	n|dk    r|	|         }	|	                    d	 
          }	|	||                                <   t          j        d|           5 }
|                                 D ]@\  }}	|	                    |
|d           |
j        |         }|                    dd           A	 d d d            d S # 1 swxY w Y   d S )N)clave_agentenombre_aseguradonumero_polizanumero_recibofecha_vencimientofecha_periodo_gracia
forma_pagoimportesecuencia_recibor|  compromiso_pago_fechacompromiso_pago_observacion)r  r  r  r  r  r  ramor  r  conductor|  r  r  )r  r  r  r  r  r  r  r  prima_originalr|  r  r  )r  r  r  r  r  r  r  r  r  r  telefonor  r  r   r   r   afirmec                 R    |                      dd                                          S NrY  rd  rj  titlexs    rU   <lambda>z$generarXLSPorPagar.<locals>.<lambda>       QYYsC%8%8%>%>%@%@ rW   r8  r  F
sheet_nameindexA:Zr*  	r9  pd	DataFramerenameupperExcelWriterto_excelsheets
set_columnrP  r   columnas_qualitascolumnas_gnpcolumnas_axacolumnas_afirmedataframes_por_pestanar   recibosdfwriter	worksheets               rU   generarXLSPorPagarr    s       ,  ,
  /  !& 7 7mW	g		B 
"" bb	%		lbb	%		lbb	(	"	"ob 
@@	A	AB 57=..0011	~_~__`` 	&dj399;; & &rkk&]%k@@@ -.i 5"%%%%&	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   AD%%D),D)c                 d   g d}g d}g d}g d}i }|                                  D ]\  }}t          j        |          }	|dk    r	|	|         }	n,|dk    r	|	|         }	n|dk    r	|	|         }	n|dk    r|	|         }	|	                    d	 
          }	|	||                                <   t          j        d|           5 }
|                                 D ]@\  }}	|	                    |
|d           |
j        |         }|                    dd           A	 d d d            d S # 1 swxY w Y   d S )N)	r  r  r  r  r  
prima_neta
fecha_pagor  r|  )	r  r  r  r  r  r  r  r  r|  )r  r  r  r  r  r  r  r|  )r  r  r  r  r  r  r  r  r   r   r   r  c                 R    |                      dd                                          S r  r  r  s    rU   r  z#generarXLSPagados.<locals>.<lambda>D  r  rW   r  r  Fr  r  r*  r  r  s               rU   generarXLSPagadosr    s     
  ,  ,  /  !& 7 7mW	g		B 
"" bb	%		lbb	%		lbb	(	"	"ob 
@@	A	AB 57=..0011	~_~__`` 	&dj399;; & &rkk&]%k@@@ -.i 5"%%%%&	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r  c                 t    t           j                            |           }|dz  }|dz  }t          |d          S )zObtiene el peso de un archivo en megabytes (MB).

    Args:
        ruta_archivo (str): La ruta completa al archivo.

    Returns:
        float: El peso del archivo en MB.
    i   r5  )rD   rE   getsizeround)r  
peso_bytespeso_kilobytespeso_megabytess       rU   obtener_peso_archivo_mbr  T  s;     ..J$&N#d*N###rW   c                    K   d}| j                             | |            d {V }t          |d          5 }|                    |                                 d {V            d d d            n# 1 swxY w Y   |S )Nz*https://wsoft1.s3.us-east-1.amazonaws.com/wb)requestr   r  writebody)rT   r~   rutaArchivo
URLS3_FILEresponser  s         rU   descargarReciboParaWhatsappr  c  s      ;*<##
%9C%9%9;;;;;;;;(K #!GG(--//!!!!!!"""# # # # # # # # # # # # # # #	s   .A33A7:A7c                    K   t          j        |d          }t          | dd          5 }|                    |           d d d            n# 1 swxY w Y   dS )NF)ensure_asciirM  zutf-8)encodingT)rs   dumpsr  r  )r   r>  
datos_jsonrQ  s       rU   guardarReporteSubidar  j  s      z%e444*D#((( DJJz              	s   AAAc                  P    g d} t          j                    j        }| |dz
           S )N)EneroFebreroMarzoAbrilMayoJunioJulioAgosto
SeptiembreOctubre	Noviembre	Diciembrere  )r   r   month)meses
mes_actuals     rU   meses_hasta_diciembrer  q  s2      % |~~#*	zA~	rW   )F)Tr   )Npandasr  ru   rs   sysr   rD   r   rG  r6  playwright.async_apir   r   collectionsr   r   r   playwright_stealthr   r_  r	   rt   r   rb   rd   rV   rZ   r_   ri   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r   r  r'  rD  rK  rR  r]  rb  rs  r  r  r  r  r  r  r  r  rl   rW   rU   <module>r     su   L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L L 9 9 9 9 9 9 9 9 # # # # # # ( ( ( ( ( ( ( ( & & & & & &       B
      G G G GT    
/ / /  5 5 55 5 55 5 55 5 55 5 55 5 5	F 	F 	F	 	 	5 5 5	 	 	5 5 5	 	 	5 5 5
5 5 55 5 55 5 55 5 55 5 55 5 5, , ,
5 5 55 5 55 5 55 5 55 5 5	 	 		 	 		 	 	  2& 2& 2&l3 3 3 3n       L> > >  2E E E
% % %# # #  + + +"
+ 
+ 
+% % %9& 9& 9&x4& 4& 4&l$ $ $        rW   