+
    {j                     $   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt RtRt	] P                  P                  R4      t] P                  P                  ]R4      t] P                  P                  ]R4      tR	 tR
 tRR ltRR ltR tRR ltR# )    N)datetime)ThreadPoolExecutorz https://prod.mydimomaintmx.cloudSERRATECz	~/Desktopzcomentarios.jsonzcomentarios_cache.jsonc                    \         P                  P                  V 4      '       d9    \        V R RR7      ;_uu_ 4       p\        P
                  ! V4      uuRRR4       # V#   + '       g   i     T# ; i  \         d    Tu # i ; i)rutf-8encodingN)ospathexistsopenjsonload	Exception)r   defaultfs   && *C:\Users\ESI FRANCE\Desktop\comentarios.py_carregar_jsonr      sj    	ww~~d	dC'22ayy| 32 N	 32 N  	N	s.   A4 A 
A4  A1	+A4 1A4 4BBc           	         \         P                  ! \         P                  P                  V 4      R R7       \	        V RRR7      ;_uu_ 4       p\
        P                  ! WR^R7       RRR4       R#   + '       g   i     R# ; i)T)exist_okwr   r	   F)ensure_asciiindentN)r   makedirsr   dirnamer   r   dump)r   datar   s   && r   _guardar_jsonr      sM    KK%5	dC'	*	*a		$a8 
+	*	*	*s   A00B	c                8  "   \          R\         R2pRRV 2RRR\        /pRV/pT;_uu_4       GR	j  xL
  \        ^4       EFL  p V P                  WVV\        P
                  ! VR
7      R7      ;_uu_4       GR	j  xL
 p	V	P                  ^8X  d@   YP                  4       G R	j  xL
 3uuR	R	R	4      GR	j  xL
  u uuR	R	R	4      GR	j  xL
  # V	P                  R8X  d-   VRR/3uuR	R	R	4      GR	j  xL
  u uuR	R	R	4      GR	j  xL
  # V	P                  R8X  d:   \        P                  ! ^V,          4      G R	j  xL
   R	R	R	4      GR	j  xL
  EK  VRRV	P                   2/3uuR	R	R	4      GR	j  xL
  u uuR	R	R	4      GR	j  xL
  # 	  VRR/3uuR	R	R	4      GR	j  xL
  #  ELy EL2 EL L L L L L| Lm LH L6  + GR	j  xL 
 '       g   i     EK  ; i  \        P                  \        P                  3 dp   p
T^8X  d7   TRR\        T
4      P                   2/3u R	p
?
u uuR	R	R	4      GR	j  xL 
  # \        P                  ! ^T,           4      G R	j  xL 
   R	p
?
EK/  R	p
?
ii ; i L  + GR	j  xL 
 '       g   i     R	# ; i5i)u?   Busca os detalhes completos de uma OT (incluindo comentários)./z/api/workOrderReader/GetAuthorizationzBearer zContent-Typezapplication/jsontenantidN)total)headersparamstimeouti  _error401_TOKEN_EXPIRADOi  HTTP_CONN_MAX_RETRIES)BASE_URLTENANTrangegetaiohttpClientTimeoutstatusr   asynciosleepTimeoutErrorClientErrortype__name__)sessionot_idtoken	semaphorer(   urlr&   r'   	tentativarespes   &&&&&      r   	_fetch_otrC   !   s/    Jax7
8C75'**&G
 E]FyyqI3";;#11@ '    {{c)$IIK&77   yy +$x1E&FF   yy +%mmAN;;;     %x51F&GG   yy!& x//) yy
 '8   <     (('*=*=> 3> 8uT!W5E5E4F-G"HHH% yy& mmA	M22223! yyys  2JF-JI=	5G$>F0?G$%G'F3(G,G$9F6:G$>I= JF8JG)G$6F:7G$;I==J
F<J1GF>GG$G 
G$I=G,G$9G:G$>I= JGJI=J'I;(J0G$3G6G$8J:G$<J>G G$G$JG!G
G!G!G$I=!G$$%I8		"I3	+I8	,I=2J?I J I3	&I)'I3	,I=3I8	8I=;J=J	J
J	J		Jc                  "   \         P                  ! V4      p\        P                  ! V^,          VR7      p\        P                  ! VR7      ;_uu_4       GRj  xL
 pV  Uu. uF  p\        WVW4      NK  	  pp\         P                  ! V!  G Rj  xL
 pRRR4      GRj  xL
  \        X4      #  LVu upi  L& L  + GRj  xL 
 '       g   i     L/; i5i)u<   Busca todas as OTs em paralelo, com limite de concorrência.)limitlimit_per_host)	connectorN)r5   	Semaphorer2   TCPConnectorClientSessionrC   gatherdict)	ot_idsr=   concorrenciar>   rG   r;   r<   tarefas
resultadoss	   &&&      r   
_fetch_allrQ   B   s     !!,/I$$<!+;LYI$$y999WLRSF59WU>FS">>733
 :9 
 :S3 :999sl   ACB2CB=$B49B=B9B=C"B;#C4B=;C=C	C
C	C	Cc                   . pV P                  R4      ;'       g    .  F  pTP                  RVP                  R4      ;'       g    / P                  RR4      RVP                  R4      RVP                  R	4      ;'       g    VP                  R
4      ;'       g    R/4       K  	  . pV P                  R4      ;'       g    .  FP  pTP                  RVP                  R4      ;'       g    / P                  RR4      RVP                  R4      /4       KR  	  RV P                  R4      RV P                  R4      RV P                  R4      ;'       g    / P                  R4      RV P                  R4      ;'       g    / P                  R4      RV P                  R4      ;'       g    / P                  R4      RV P                  R4      RV P                  R4      RV P                  R4      RV P                  R4      R\        V P                  R4      \        4      '       d+   V P                  R4      ;'       g    / P                  R4      MV P                  R4      RVRVR\        P
                  ! 4       P                  4       /# )z5Extrai apenas os campos que interessam para pesquisa.commentListauthoruserfullNameDesconhecidodatecreationDateTimetextcommentcommentHtml 
signaturessigner	signatorysignatureDateTimecodenamestate	assetCodeasset	assetNamebeginDateTimeendDateTimelastModificationDateTime
technicianremedycomments	synced_at)r1   append
isinstancerL   r   now	isoformat)ot_detalhescomentarioscassinaturasss   &    r   _extrair_comentariosrx   L   s3   Koom,222quuV}**//
NKAEE,-AEE)$BBm(<BB
 	 3 Kool+11r1quu[)//R44ZPAEE-.
 	 2 	''+//'*00b55f=koog.44"99&Akoog.44"99&A9{}5"KOO4N$Okool3:koo^fNgimCnCn;??8,2277?t  uD  uD  EM  uNKkX\\^--/     c           
        V P                   '       g   \        R4       R# \        \        P                  P                  \        R4      . 4      pV'       g   \        R4       R# \        \        / 4      p. pV F  pVP                  R4      pV'       g   K  V'       d   VP                  RR4      p	V	R#9   d   KA  VP                  V4      p
V
'       dC   VP                  R4      ;'       g    VP                  R	4      pV
P                  R4      V8X  d   K  VP                  V4       K  	  V'       d   VRV pV'       g   \        R
4       R# \        R\        V4       RV R24       \        P                  ! 4       p\        P                  ! \        W`P                   V4      4      p^ ^ rVP                  4        F<  w  ppRV9   d   VR,          R8X  d
   V^,          pK&  \!        V4      WX&   V^,          pK>  	  \#        \        V4       \        P                  P                  \        R4      p\%        VRRR7      ;_uu_ 4       pVP                  4        F8  w  ppVP'                  \(        P*                  ! RV/VCRR7      R,           4       K:  	  RRR4       \        P                  ! 4       V,
          p\        RVR R24       \        RV 24       \        RV 24       \        R\        V4       R24       \        R\         24       \        RV R\        P                  P-                  V4      R ,          R ,          R! R"24       R#   + '       g   i     L; i)$u8  
Sincroniza comentários de todas as OTs (ou apenas das abertas).

Args:
    api: instância de DimoMaintAPI (para aceder ao token)
    limite: máximo de OTs a sincronizar (None = todas)
    concorrencia: número de pedidos em paralelo
    apenas_abertas: se True, só sincroniza OTs não encerradas + recentes
u,   ❌ Sem token para sincronizar comentários.Nzworkorders.jsonuO   ⚠️ workorders.json vazio ou inexistente. Executa o sync principal primeiro.r$   stateIdr]   rj   rh   u5   ✅ Nada para sincronizar — cache está atualizada.u   📥 A sincronizar u    OTs (concorrência=z)...r)   r*   zcomentarios.jsonlr   r   r	   F)r   
u   ✅ Sync concluída em z.1frw   u      📥 Novos/atualizados: u      ❌ Erros de token: u      💾 Cache total: z OTsu      📄 z  (i   z.2fz MB))z$ada41e02-5e6a-4dc7-9f5c-e6b14340f1a6z$d67894ef-2d53-4e63-a840-71089d2cc851)r=   printr   r   r   joinDESKTOPCOMENTARIOS_CACHEr1   ro   lentimer5   runrQ   itemsrx   r   r   writer   dumpsgetsize)apilimiterN   apenas_abertas
workorderscachea_sincronizarwor<   estadocachedlast_modt0rP   novoserros_tokendetalhes
jsonl_pathr   dadosdurs   &&&&                 r   sync_comentariosr   n   s    999<=  W6G H"MJ_` ,b1E Mt VVIr*F B B 5!vv89TTRVVO=THzz45AU#) , %gv.EF	M 233G~UY
Z[	B Zyy,OPJ A;%++-xx!%99q +H5
 . #U+ g':;J	j#	0	0A!KKMLE5GGDJJe5u5EJTQR * 
1 ))+
C	#C9A
./	'w
/0	#K=
12	!#e*T
23	H&'
()	HZLBGGOOJ$?$DT$I##Nd
ST 
1	0s   AMM	)   )   )Nr   T)r   r   r   r5   r2   r   concurrent.futuresr   r.   r/   r   
expanduserr   r~   COMENTARIOS_FILEr   r   r   rC   rQ   rx   r    ry   r   <module>r      s    	      1-	
''

[
)77<<);< GGLL*BC 90BDUUry   