
    Rh!                         d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ  eddg	      Zd
ededefdZej                  d       ee      fdedefd       Zy)    N)	APIRouterDepends)Session)get_db)AuthenticationClass)ExternalApiCredentialsz/summary-indicatorszSummary Indicators)prefixtagsurlcredentialsdbc                 F   dd|j                    i}t        j                  | |      }|j                  dk(  sd|j                  j                         v rMt        |      j                  |j                  |j                        }dd| i}t        j                  | |      }|S )ud   Función helper que intenta usar el token actual, y si falla (401 o token-invalido) genera uno nuevoAuthorizationzBearer )headersi  ztoken-invalido)
external_tokenrequestsgetstatus_codetextlowerr   create_external_tokenrutpassword)r   r   r   r   responsefresh_tokens         R/var/www/intrajisbackend.com/public_html/app/backend/routers/summary_indicators.py'make_request_with_fresh_token_if_neededr      s     '+*D*D)E FGG||C1H s"&6(--:M:M:O&O)"-CCKOOU`UiUij"gk]$;<<<W5O    z/summaryc                 <    d}t        || |      }d|j                  iS )uI   
    Obtiene resumen de indicadores económicos desde la API externa
    z/https://api.jisreportes.com/indicadores/summarymessage)r   r   )r   r   r   r   s       r   get_summary_indicatorsr!      s&    
 <C6sKLHx}}%%r   )r   fastapir   r   sqlalchemy.ormr   app.backend.db.databaser   (app.backend.classes.authentication_classr   app.backend.schemasr   summary_indicatorsstrr   postr!    r   r   <module>r+      s}     & " * H 6 
	 
 CY _f  $NUV\o &(> &G & %&r   