
    rbi                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
  G d	 d
ed          Z G d d          ZdS )u>   Weather forecast Python model for the Météo-France REST API.    )datetime)Any)Dict)List)	TypedDict)utc)$timestamp_to_datetime_with_locale_tzc                       e Zd ZU dZeeef         ed<   eed<   e	eeef                  ed<   e	eeef                  ed<   e	eeef                  ed<   dS )ForecastDatazNDescribing the data structure of the forecast object returned by the REST API.position
updated_ondaily_forecastforecastprobability_forecastN)
__name__
__module____qualname____doc__r   strr   __annotations__intr        n/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/meteofrance_api/model/forecast.pyr   r      s         XX38nOOOc3h((((4S>""""tCH~......r   r   F)totalc                      e Zd ZdZdeddfdZedeee	f         fd            Z
edefd            Zedeeee	f                  fd            Zedeeee	f                  fd	            Zedeeee	f                  fd
            Zedeee	f         fd            Zedeee	f         fd            Zedeee	f         fd            ZdedefdZdS )Forecasta  Class to access the results of a `forecast` API request.

    Attributes:
        position: A dictionary with metadata about the position of the forecast place.
        updated_on: A timestamp as int corresponding to the latest update date.
        daily_forecast: A list of dictionaries to describe the daily forecast for the
            next 15 days.
        forecast: A list of dictionaries to describe the hourly forecast for the next
            days.
        probability_forecast: A list of dictionaries to describe the event probability
            forecast (rain, snow, freezing) for next 10 days.
        today_forecast: A dictionary corresponding to the daily forecast for the current
        day.
        nearest_forecast: A dictionary corresponding to the nearest hourly forecast.
        current_forecast: A dictionary corresponding to the hourly forecast for the
            current hour.
    raw_datareturnNc                     || _         dS )zInitialize a Forecast object.

        Args:
            raw_data: A dictionary representing the JSON response from 'forecast' REST
                API request. The structure is described by the ForecastData class.
        Nr   )selfr   s     r   __init__zForecast.__init__+   s     !r   c                     | j         d         S )z0Return the position information of the forecast.r   r!   r"   s    r   r   zForecast.position4        }Z((r   c                     | j         d         S )z,Return the update timestamp of the forecast.r   r!   r%   s    r   r   zForecast.updated_on9   s     }\**r   c                     | j         d         S )z1Return the daily forecast for the following days.r   r!   r%   s    r   r   zForecast.daily_forecast>   s     }-..r   c                     | j         d         S )zReturn the hourly forecast.r   r!   r%   s    r   r   zForecast.forecastC   r&   r   c                 8    | j                             dg           S )z"Return the weather event forecast.r   )r   getr%   s    r   r   zForecast.probability_forecastH   s     }  !7<<<r   c                     | j         d         S )zReturn the forecast for today.r   )r   r%   s    r   today_forecastzForecast.today_forecastM   s     "1%%r   c                     t          t          j        t          j                                                                        t          | j        fd          }|d         S )z#Return the nearest hourly forecast.c                 4    t          | d         z
            S )Ndt)abs)xnow_timestamps    r   <lambda>z+Forecast.nearest_forecast.<locals>.<lambda>[   s    #ag566 r   )keyr   )r   r   localizer   utcnow	timestampsortedr   )r"   sorted_forecastr3   s     @r   nearest_forecastzForecast.nearest_forecastR   sd     CL):):;;EEGGHH !M6666
 
 
 q!!r   c           	         t          t          j        t          j                                        ddd                                                              }d | j        D             }|                    || j	                  S )z(Return the forecast of the current hour.r   )minutesecondmicrosecondc                      i | ]}|d          |S )r0   r   ).0items     r   
<dictcomp>z-Forecast.current_forecast.<locals>.<dictcomp>i   s    KKKTT
DKKKr   )
r   r   r6   r   r7   replacer8   r   r+   r;   )r"   current_hour_timestampforecast_by_datetimes      r   current_forecastzForecast.current_forecast_   s     "%L!!))1!)LL ikk"
 "
  LKT]KKK $''(>@UVVVr   r8   c                 8    t          || j        d                   S )a.  Convert timestamp in datetime in the forecast location timezone (Helper).

        Args:
            timestamp: An integer to describe the UNIX timestamp.

        Returns:
            Datetime instance corresponding to the timestamp with the timezone of the
                forecast location.
        timezone)r	   r   )r"   r8   s     r   timestamp_to_locale_timez!Forecast.timestamp_to_locale_timen   s"     4t}Z0
 
 	
r   )r   r   r   r   r   r#   propertyr   r   r   r   r   r   r   r   r   r   r-   r;   rG   r   rJ   r   r   r   r   r      s        $! !$ ! ! ! ! )$sCx. ) ) ) X) +C + + + X+ /T#s(^ 4 / / / X/ )$tCH~. ) ) ) X) =d4S>&: = = = X= &S#X & & & X& 
"$sCx. 
" 
" 
" X
" W$sCx. W W W XW
# 
( 
 
 
 
 
 
r   r   N)r   r   typingr   r   r   r   pytzr   meteofrance_api.helpersr	   r   r   r   r   r   <module>rO      s    D D                                     H H H H H H/ / / / /9E / / / /b
 b
 b
 b
 b
 b
 b
 b
 b
 b
r   