U
    ҭcU                     @   sF  d Z ddlZddlmZ dddddd	d
dddddddddddddhZdhZdddhZeeA eA Zdddddddd	d
dddddddddddddd d!d"d#hZd$d%dd&d'd(hZ	d)d*d+d,ddd-d.d/d0d1d2d3d4d5d6d7dhZ
ee	A e
A Zdd.hZd8ZdNd9d:ZdOd<d=ZdPd>d?ZdQdAdBZdRdDdEZdSdFdGZdTdHdIZdUdJdKZdVdLdMZdS )Wz+Performs requests to the Google Places API.    N)convertZbusiness_statusZformatted_addressZgeometryzgeometry/locationzgeometry/location/latzgeometry/location/lngzgeometry/viewportzgeometry/viewport/northeastzgeometry/viewport/northeast/latzgeometry/viewport/northeast/lngzgeometry/viewport/southwestzgeometry/viewport/southwest/latzgeometry/viewport/southwest/lngZiconnameZpermanently_closedZphotosplace_idZ	plus_codetypesZopening_hoursZprice_levelZratingZuser_ratings_totalZaddress_componentZadr_addressZphototypeurlZ
utc_offsetZvicinityZwheelchair_accessible_entranceZformatted_phone_numberZinternational_phone_numberZcurrent_opening_hoursZsecondary_opening_hoursZwebsiteZcurbside_pickupZdeliveryZdine_inZeditorial_summaryZ
reservableZreviewZreviewsZserves_beerZserves_breakfastZserves_brunchZserves_dinnerZserves_lunchZserves_vegetarian_foodZserves_wineZtakeoutzYFields, %s, are deprecated. Read more at https://developers.google.com/maps/deprecations.c           
      C   s   ||d}|dkr&|dkr&t d| |rt|t@ }|rRtttt| t t|t	 }|r~t dd
t	d
|f td||d< |rd	d
ddg}	|dd |	krt d|	 ||d< |r||d< | d|S )a  
    A Find Place request takes a text input, and returns a place.
    The text input can be any kind of Places data, for example,
    a name, address, or phone number.

    :param input: The text input specifying which place to search for (for
                  example, a name, address, or phone number).
    :type input: string

    :param input_type: The type of input. This can be one of either 'textquery'
                  or 'phonenumber'.
    :type input_type: string

    :param fields: The fields specifying the types of place data to return. For full details see:
                   https://developers.google.com/places/web-service/search#FindPlaceRequests
    :type fields: list

    :param location_bias: Prefer results in a specified area, by specifying
                          either a radius plus lat/lng, or two lat/lng pairs
                          representing the points of a rectangle. See:
                          https://developers.google.com/places/web-service/search#FindPlaceRequests
    :type location_bias: string

    :param language: The language in which to return results.
    :type language: string

    :rtype: result dict with the following keys:
            status: status code
            candidates: list of places
    )inputZ	inputtypeZ	textqueryZphonenumberz{Valid values for the `input_type` param for `find_place` are 'textquery' or 'phonenumber', the given value is invalid: '%s'zeValid values for the `fields` param for `find_place` are '%s', these given field(s) are invalid: '%s'', ',fieldsZipbiasZpointZcircleZ	rectangle:r   z0location_bias should be prefixed with one of: %sZlocationbiaslanguagez&/maps/api/place/findplacefromtext/json)
ValueErrorsetDEPRECATED_FIELDSwarningswarnDEPRECATED_FIELDS_MESSAGEstrlistDeprecationWarningPLACES_FIND_FIELDSjoinr   	join_listsplit_request)
clientr   Z
input_typer   Zlocation_biasr   paramsdeprecated_fieldsinvalid_fieldsZvalid r    N/home/ubuntu/graampay/app_env/lib/python3.8/site-packages/googlemaps/places.py
find_place   s<    !
r"   Fc                 C   s    t | d|||||||||	|
dS )a(  
    Places search.

    :param query: The text string on which to search, for example: "restaurant".
    :type query: string

    :param location: The latitude/longitude value for which you wish to obtain the
        closest, human-readable address.
    :type location: string, dict, list, or tuple

    :param radius: Distance in meters within which to bias results.
    :type radius: int

    :param language: The language in which to return results.
    :type language: string

    :param min_price: Restricts results to only those places with no less than
        this price level. Valid values are in the range from 0 (most affordable)
        to 4 (most expensive).
    :type min_price: int

    :param max_price: Restricts results to only those places with no greater
        than this price level. Valid values are in the range from 0 (most
        affordable) to 4 (most expensive).
    :type max_price: int

    :param open_now: Return only those places that are open for business at
        the time the query is sent.
    :type open_now: bool

    :param type: Restricts the results to places matching the specified type.
        The full list of supported types is available here:
        https://developers.google.com/places/supported_types
    :type type: string

    :param region: The region code, optional parameter.
        See more @ https://developers.google.com/places/web-service/search
    :type region: string

    :param page_token: Token from a previous search that when provided will
        returns the next page of results for the same search.
    :type page_token: string

    :rtype: result dict with the following keys:
        results: list of places
        html_attributions: set of attributions which must be displayed
        next_page_token: token for retrieving the next page of results
    text)
querylocationradiusr   	min_price	max_priceopen_nowr   region
page_token)_places)r   r$   r%   r&   r   r'   r(   r)   r   r*   r+   r    r    r!   places   s    =r-   c                 C   s`   |s|st d|	dkr>|s.|s.|
s.t dn|dk	r>t dt| d|||||||||	|
|dS )a	  
    Performs nearby search for places.

    :param location: The latitude/longitude value for which you wish to obtain the
                     closest, human-readable address.
    :type location: string, dict, list, or tuple

    :param radius: Distance in meters within which to bias results.
    :type radius: int

    :param region: The region code, optional parameter.
        See more @ https://developers.google.com/places/web-service/search
    :type region: string

    :param keyword: A term to be matched against all content that Google has
                    indexed for this place.
    :type keyword: string

    :param language: The language in which to return results.
    :type language: string

    :param min_price: Restricts results to only those places with no less than
                      this price level. Valid values are in the range from 0
                      (most affordable) to 4 (most expensive).
    :type min_price: int

    :param max_price: Restricts results to only those places with no greater
                      than this price level. Valid values are in the range
                      from 0 (most affordable) to 4 (most expensive).
    :type max_price: int

    :param name: One or more terms to be matched against the names of places.
    :type name: string or list of strings

    :param open_now: Return only those places that are open for business at
                     the time the query is sent.
    :type open_now: bool

    :param rank_by: Specifies the order in which results are listed.
                    Possible values are: prominence (default), distance
    :type rank_by: string

    :param type: Restricts the results to places matching the specified type.
        The full list of supported types is available here:
        https://developers.google.com/places/supported_types
    :type type: string

    :param page_token: Token from a previous search that when provided will
                       returns the next page of results for the same search.
    :type page_token: string

    :rtype: result dict with the following keys:
            status: status code
            results: list of places
            html_attributions: set of attributions which must be displayed
            next_page_token: token for retrieving the next page of results

    z/either a location or page_token arg is requiredZdistancezOeither a keyword, name, or type arg is required when rank_by is set to distanceNz:radius cannot be specified when rank_by is set to distanceZnearby)r%   r&   keywordr   r'   r(   r   r)   rank_byr   r+   )r   r,   )r   r%   r&   r.   r   r'   r(   r   r)   r/   r   r+   r    r    r!   places_nearby  s4    Hr0      c                 C   s   ||d}|r||d< |r(t ||d< |r4||d< |r@||d< |rL||d< |	r`t d|	|d< |
rld	|d
< |rx||d< |r||d< |r||d< |r||d< d| }| ||S )zl
    Internal handler for ``places`` and ``places_nearby``.
    See each method's docs for arg details.
    )ZminpriceZmaxpricer$   r%   r&   r.   r    r   trueZopennowZrankbyr   r*   Z	pagetokenz/maps/api/place/%ssearch/json)r   latlngr   r   )r   url_partr$   r%   r&   r.   r   r'   r(   r   r)   r/   r   r*   r+   r   r   r    r    r!   r,   y  s2    
r,   most_relevantc           
      C   s   d|i}|rpt |t@ }|r4tttt| t t |t }	|	r`t	dd
td
|	f td||d< |r|||d< |r||d< |rd|d	< |r||d
< | d|S )a  
    Comprehensive details for an individual place.

    :param place_id: A textual identifier that uniquely identifies a place,
        returned from a Places search.
    :type place_id: string

    :param session_token: A random string which identifies an autocomplete
                          session for billing purposes.
    :type session_token: string

    :param fields: The fields specifying the types of place data to return,
                   separated by a comma. For full details see:
                   https://cloud.google.com/maps-platform/user-guide/product-changes/#places
    :type input: list

    :param language: The language in which to return results.
    :type language: string

    :param reviews_no_translations: Specify reviews_no_translations=True to disable translation of reviews; reviews_no_translations=False (default) enables translation of reviews.
    :type reviews_no_translations: bool

    :param reviews_sort: The sorting method to use when returning reviews.
                         Can be set to most_relevant (default) or newest.
    :type reviews_sort: string

    :rtype: result dict with the following keys:
        result: dict containing place details
        html_attributions: set of attributions which must be displayed
    Zplaceidz`Valid values for the `fields` param for `place` are '%s', these given field(s) are invalid: '%s'r	   r
   r   r   sessiontokenr3   reviews_no_translationsreviews_sortz/maps/api/place/details/json)r   r   r   r   r   r   r   r   PLACES_DETAIL_FIELDSr   r   r   r   r   )
r   r   session_tokenr   r   r8   r9   r   r   r   r    r    r!   place  s2    'r<   c                 C   sR   |s|st dd|i}|r$||d< |r0||d< | jd|dd dd	id
}| S )a
  
    Downloads a photo from the Places API.

    :param photo_reference: A string identifier that uniquely identifies a
        photo, as provided by either a Places search or Places detail request.
    :type photo_reference: string

    :param max_width: Specifies the maximum desired width, in pixels.
    :type max_width: int

    :param max_height: Specifies the maximum desired height, in pixels.
    :type max_height: int

    :rtype: iterator containing the raw image data, which typically can be
        used to save an image file locally. For example:

    .. code-block:: python

        f = open(local_filename, 'wb')
        for chunk in client.places_photo(photo_reference, max_width=100):
            if chunk:
                f.write(chunk)
        f.close()
    z)a max_width or max_height arg is requiredZphotoreferenceZmaxwidthZ	maxheightz/maps/api/place/photoc                 S   s   | S )Nr    )responser    r    r!   <lambda>      zplaces_photo.<locals>.<lambda>streamT)Zextract_bodyZrequests_kwargs)r   r   Ziter_content)r   Zphoto_reference	max_widthZ
max_heightr   r=   r    r    r!   places_photo  s    rB   c                 C   s    t | d|||||||||	|
dS )a  
    Returns Place predictions given a textual search string and optional
    geographic bounds.

    :param input_text: The text string on which to search.
    :type input_text: string

    :param session_token: A random string which identifies an autocomplete
                          session for billing purposes.
    :type session_token: string

    :param offset: The position, in the input term, of the last character
                   that the service uses to match predictions. For example,
                   if the input is 'Google' and the offset is 3, the
                   service will match on 'Goo'.
    :type offset: int

    :param origin: The origin point from which to calculate straight-line distance
                    to the destination (returned as distance_meters).
                    If this value is omitted, straight-line distance will
                    not be returned.
    :type origin: string, dict, list, or tuple

    :param location: The latitude/longitude value for which you wish to obtain the
                     closest, human-readable address.
    :type location: string, dict, list, or tuple

    :param radius: Distance in meters within which to bias results.
    :type radius: int

    :param language: The language in which to return results.
    :type language: string

    :param types: Restricts the results to places matching the specified type.
        The full list of supported types is available here:
        https://developers.google.com/places/web-service/autocomplete#place_types
    :type types: string

    :param components: A component filter for which you wish to obtain a geocode.
        Currently, you can use components to filter by up to 5 countries for
        example: ``{'country': ['US', 'AU']}``
    :type components: dict

    :param strict_bounds: Returns only those places that are strictly within
        the region defined by location and radius.
    :type strict_bounds: bool

    :rtype: list of predictions

     )	r;   offsetoriginr%   r&   r   r   
componentsstrict_bounds_autocomplete)r   
input_textr;   rD   rE   r%   r&   r   r   rF   rG   r    r    r!   places_autocomplete#  s    ?rK   c              	   C   s   t | d|||||dS )a\  
    Returns Place predictions given a textual search query, such as
    "pizza near New York", and optional geographic bounds.

    :param input_text: The text query on which to search.
    :type input_text: string

    :param offset: The position, in the input term, of the last character
        that the service uses to match predictions. For example, if the input
        is 'Google' and the offset is 3, the service will match on 'Goo'.
    :type offset: int

    :param location: The latitude/longitude value for which you wish to obtain the
        closest, human-readable address.
    :type location: string, dict, list, or tuple

    :param radius: Distance in meters within which to bias results.
    :type radius: number

    :param language: The language in which to return results.
    :type language: string

    :rtype: list of predictions
    r$   )rD   r%   r&   r   rH   )r   rJ   rD   r%   r&   r   r    r    r!   places_autocomplete_queryr  s    rL   c                 C   s   d|i}|r||d< |r ||d< |r2t ||d< |rDt ||d< |rP||d< |r\||d< |	rh|	|d< |
rt|
d	kst|
 d
 dkrtdt |
|d< |rd|d< d| }| ||dg S )zw
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    r   r7   rD   rE   r%   r&   r   r      r   Zcountryz%Only country components are supportedrF   r3   Zstrictboundsz#/maps/api/place/%sautocomplete/jsonZpredictions)	r   r4   lenr   keysr   rF   r   get)r   r5   rJ   r;   rD   rE   r%   r&   r   r   rF   rG   r   r   r    r    r!   rI     s.     rI   )NNN)
NNNNNNFNNN)NNNNNNNFNNN)NNNNNr   r1   NFNNNN)NNNFr6   )NN)	NNNNNNNNF)NNNN)	NNNNNNNNF)__doc__r   
googlemapsr   ZPLACES_FIND_FIELDS_BASICZPLACES_FIND_FIELDS_CONTACTZPLACES_FIND_FIELDS_ATMOSPHEREr   ZPLACES_DETAIL_FIELDS_BASICZPLACES_DETAIL_FIELDS_CONTACTZPLACES_DETAIL_FIELDS_ATMOSPHEREr:   r   r   r"   r-   r0   r,   r<   rB   rK   rL   rI   r    r    r    r!   <module>   sL  

     
I          
O           
i             
6     
G
3         
P       
*         