
    rbi4                         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
 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          ZdS )u'   Client for the Météo-France REST API.    )List)Optional   )COASTAL_DEPARTMENT_LIST)METEOFRANCE_API_TOKEN)METEOFRANCE_API_URL)CurrentPhenomenons)Forecast)Full)Observation)PictureOfTheDayPlace)Rain)WarningDictionary)MeteoFranceSessionc            
       ^   e Zd ZdZddee         ddfdZ	 	 ddedee         dee         dee         fd	Z		 dde
de
dedefdZ	 ddededefdZ	 dde
de
dedefdZ	 ddededefdZdde
de
dedefdZ	 d dedededefdZ	 d!dededefdZd"dedefdZddedefdZd"dedefdZdS )#MeteoFranceClientu   Proxy to the Météo-France REST API.

    You will find methods and helpers to request weather forecast, rain forecast and
    weather alert bulletin.
    Naccess_tokenreturnc                 .    t          |          | _        dS )zInitialize the API and store the auth so we can make requests.

        Args:
            access_token: a string containing the authentication token for the REST API.
        N)r   session)selfr   s     f/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/meteofrance_api/client.py__init__zMeteoFranceClient.__init__"   s     *,77    search_querylatitude	longitudec                     d|i}|||d<   |||d<   | j                             dd|          }d |                                D             S )	a  Search the places (cities) linked to a query by name.

        You can add GPS coordinates in parameter to search places around a given
        location.

        Args:
            search_query: A complete name, only a part of a name or a postal code (for
                France only) corresponding to a city in the world.
            latitude: Optional; Latitude in degree of a reference point to order
                results. The nearest places first.
            longitude: Optional; Longitude in degree of a reference point to order
                results. The nearest places first.

        Returns:
            A list of places (Place instance) corresponding to the query.
        qNlatlongetplacesparamsc                 ,    g | ]}t          |          S  r   ).0
place_datas     r   
<listcomp>z3MeteoFranceClient.search_places.<locals>.<listcomp>L   s     @@@jj!!@@@r   )r   requestjson)r   r   r   r   r'   resps         r   search_placeszMeteoFranceClient.search_places-   sf    . |$$F5M %F5M |##E8F#CC@@DIIKK@@@@r   frlanguagec                     | j                             dd|||d          }t          |                                          S )aj  Retrieve the weather observation for a given GPS location.

        Results can be fetched in french or english according to the language parameter.

        Args:
            latitude: Latitude in degree of the GPS point corresponding to the weather
                forecast.
            longitude: Longitude in degree of the GPS point corresponding to the weather
                forecast.
            language: Optional; If language is equal "fr" (default value) results will
                be in French. All other value will give results in English.

        Returns:
            An Observation instance.
        r$   zv2/observationr"   r#   langr&   )r   r-   r   r.   r   r   r   r2   r/   s        r   get_observationz!MeteoFranceClient.get_observationQ   sK    * |###IxHH $ 
 

 499;;'''r   placec                 D    |                      |j        |j        |          S )a  Retrieve the weather observation for a given Place instance.

        Results can be fetched in french or english according to the language parameter.

        Args:
            place: Place class instance corresponding to a location.
            language: Optional; If language is equal "fr" (default value) results will
                be in French. All other value will give results in English.

        Returns:
            An Observation instance.
        )r7   r   r   r   r8   r2   s      r   get_observation_for_placez+MeteoFranceClient.get_observation_for_placem   s     " ##ENEOXNNNr   c                     | j                             dd|||d          }t          |                                          S )a  Retrieve the weather forecast for a given GPS location.

        Results can be fetched in french or english according to the language parameter.

        Args:
            latitude: Latitude in degree of the GPS point corresponding to the weather
                forecast.
            longitude: Longitude in degree of the GPS point corresponding to the weather
                forecast.
            language: Optional; If language is equal "fr" (default value) results will
                be in French. All other value will give results in English.

        Returns:
            A Forecast instance representing the hourly and daily weather forecast.
        r$   forecastr4   r&   )r   r-   r
   r.   r6   s        r   get_forecastzMeteoFranceClient.get_forecast   sK    0 |###IxHH $ 
 

 		$$$r   c                 D    |                      |j        |j        |          S )a  Retrieve the weather forecast for a given Place instance.

        Results can be fetched in french or english according to the language parameter.

        Args:
            place: Place class instance corresponding to a location.
            language: Optional; If language is equal "fr" (default value) results will
                be in French. All other value will give results in English.

        Returns:
            A Forecast instance representing the hourly and daily weather forecast.
        )r>   r   r   r:   s      r   get_forecast_for_placez(MeteoFranceClient.get_forecast_for_place   s     "   (KKKr   c                     | j                             dd|||d          }t          |                                          S )a  Retrieve the next 1 hour rain forecast for a given GPS the location.

        Results can be fetched in french or english according to the language parameter.

        Args:
            latitude: Latitude in degree of the GPS point corresponding to the rain
                forecast.
            longitude: Longitude in degree of the GPS point corresponding to the rain
                forecast.
            language: Optional; If language is equal "fr" (default value) results will
                be in French. All other value will give results in English.

        Returns:
            A Rain instance representing the next hour rain forecast.
        r$   rainr4   r&   )r   r-   r   r.   r6   s        r   get_rainzMeteoFranceClient.get_rain   sI    & |##6(9h"W"W $ 
 
 DIIKK   r   r   Fdomaindepthwith_coastal_bulletinc                 J   | j                             dd||d          }t          |                                          }|r_|t          v rV| j                             ddd|dz   i          }|                    t          |                                                     |S )a  Return the current weather phenomenons (or alerts) for a given domain.

        Args:
            domain: could be `france` or any metropolitan France department numbers on
                two digits. For some departments you can access an additional bulletin
                for coastal phenomenons. To access it add `10` after the domain id
                (example: `1310`).
            depth: Optional; To be used with domain = 'france'. With depth = 0 the
                results will show only national sum up of the weather alerts. If
                depth = 1, you will have in addition, the bulletin for all metropolitan
                France department and Andorre
            with_coastal_bulletin: Optional; If set to True (default is False), you can
                get the basic bulletin and coastal bulletin merged.

        Returns:
            A warning.CurrentPhenomenons instance representing the weather alert
            bulletin.
        r$   zv3/warning/currentphenomenons)rD   rE   r&   rD   10)r   r-   r	   r.   r   merge_with_coastal_phenomenons)r   rD   rE   rF   r/   phenomenonss         r   get_warning_current_phenomenonsz1MeteoFranceClient.get_warning_current_phenomenons   s    , |##+$u55 $ 
 
 )55  		000|++3$ftm4 ,  
 ::&tyy{{33   r   c                 H   | j                             ddd|i          }t          |                                          }|r_|t          v rV| j                             ddd|dz   i          }|                    t          |                                                     |S )a.  Retrieve a complete bulletin of the weather phenomenons for a given domain.

        For a given domain we can access the maximum alert, a timelaps of the alert
        evolution for the next 24 hours, a list of alerts and other metadata.

        Args:
            domain: could be `france` or any metropolitan France department numbers on
                two digits. For some departments you can access an additional bulletin
                for coastal phenomenons. To access it add `10` after the domain id
                (example: `1310`).
            with_coastal_bulletin: Optional; If set to True (default is False), you can
                get the basic bulletin and coastal bulletin merged.

        Returns:
            A warning.Full instance representing the complete weather alert bulletin.
        r$   z/v3/warning/fullrD   r&   zv3/warning/fullrH   )r   r-   r   r.   r   rI   )r   rD   rF   r/   full_phenomenonss        r   get_warning_fullz"MeteoFranceClient.get_warning_full   s    , |##%x.@ $ 
 

  		,, ! 	S000|++%$ftm4 ,  
 !??TYY[[@Q@QRRRr   francec                 *    t            dt           d| S )a-  Retrieve the thumbnail URL of the weather phenomenons or alerts map.

        Args:
            domain: could be `france` or any metropolitan France department numbers on
                two digits.

        Returns:
            The URL of the thumbnail representing the weather alert status.
        z/v3/warning/thumbnail?&token=z&domain=)r   r   )r   rD   s     r   get_warning_thumbnailz'MeteoFranceClient.get_warning_thumbnail(  s0     #    AV       	
r   c                     | j                             ddd|i          }t          |                                          }|S )u  Retrieves the meteorological dictionary from the Météo-France API.

        This dictionary includes information about various meteorological
        phenomena and color codes used for weather warnings.

        Args:
            language (str): The language in which to retrieve the
                dictionary data. Default is 'fr' for French. Other language codes
                can be used if supported by the API.

        Returns:
            WarningDictionary: An object containing structured data about
                meteorological phenomena and warning color codes. It has two main
                attributes: 'phenomenons' (list of PhenomenonDictionaryEntry) and
                'colors' (list of ColorDictionaryEntry).
        r$   zv3/warning/dictionaryr5   r&   )r   r-   r   r.   )r   r2   r/   
dictionarys       r   get_warning_dictionaryz(MeteoFranceClient.get_warning_dictionary8  sJ    " |##*FH3E $ 
 
 'tyy{{33
r   c           	          | j                             dd|dddd          }t           d| d	t           }t	          ||j        d
          S )zRetrieve the picture of the day image URL & description.

        Args:
            domain: could be `france`

        Returns:
            PictureOfTheDay instance with the URL and the description of the picture of
            the day.
        r$   z	v2/reportobservationzimage du jourtxt)rD   report_typereport_subtypeformatr&   z/v2/report?domain=zK&report_type=observation&report_subtype=image%20du%20jour&format=jpg&token=)	image_urldescription)r   r-   r   r   r   text)r   rD   r/   r[   s       r   get_picture_of_the_dayz(MeteoFranceClient.get_picture_of_the_dayR  s     |## ,"1	  $ 	
 	
 # . .. . ,. . 	 YtyQQRRRr   )N)NN)r1   )r   F)F)rO   )__name__
__module____qualname____doc__r   strr   r   r   r0   floatr   r7   r;   r
   r>   r@   r   rC   intboolr	   rK   r   rN   rQ   r   rT   r   r^   r)   r   r   r   r      s        8 8Xc] 8d 8 8 8 8 #'#'	A AA 3-A C=	A
 
eA A A AP 	( (( ( 	(
 
( ( ( (> O OO O 
	O O O O4 	% %% % 	%
 
% % % %D L LL L 
	L L L L,! ! !5 !C !SW ! ! ! !8 JO* **"%*BF*	* * * *Z :?'  ' ' 26' 	'  '  '  ' R
 
C 
s 
 
 
 
  s >O    4S SS S S S S S S Sr   r   N)rb   typingr   r   constr   r   r   modelr	   r
   r   r   r   r   r   r   r   r   r   r)   r   r   <module>rj      sM   - -             * * * * * * ( ( ( ( ( ( & & & & & & % % % % % %                   " " " " " "             $ $ $ $ $ $ ' ' ' ' ' 'VS VS VS VS VS VS VS VS VS VSr   