U
    h
                     @   sT   d Z ddlmZmZmZmZ ddlmZmZm	Z	 ddl
mZmZ G dd deZdS )z&Util that calls Google Scholar Search.    )AnyDictOptionalcast)	BaseModel	SecretStrroot_validator)convert_to_secret_strget_from_dict_or_envc                   @   sb   e Zd ZU dZeed< dZee ed< G dd dZ	e
ddeed	d
dZeedddZdS )GoogleJobsAPIWrapperaU  Wrapper for SerpApi's Google Scholar API

    You can create SerpApi.com key by signing up at: https://serpapi.com/users/sign_up.
    The wrapper uses the SerpApi.com python package:
    https://serpapi.com/integrations/python
    To use, you should have the environment variable ``SERPAPI_API_KEY``
    set with your API key, or pass `serp_api_key` as a named parameter
    to the constructor.
     Example:
        .. code-block:: python
        from langchain_community.utilities import GoogleJobsAPIWrapper
        google_Jobs = GoogleJobsAPIWrapper()
        google_Jobs.run('langchain')
    serp_search_engineNserp_api_keyc                   @   s   e Zd ZdZdS )zGoogleJobsAPIWrapper.ConfigZforbidN)__name__
__module____qualname__extra r   r   M/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/utilities/google_jobs.pyConfig   s   r   T)pre)valuesreturnc                 C   sR   t t|dd|d< zddlm} W n tk
r@   tdY nX |}||d< |S )z?Validate that api key and python package exists in environment.r   ZSERPAPI_API_KEYr   )SerpApiClientzigoogle-search-results is not installed. Please install it with `pip install google-search-results>=2.4.2`r   )r	   r
   Zserpapir   ImportError)clsr   r   r   r   r   r   validate_environment   s    

z)GoogleJobsAPIWrapper.validate_environment)queryr   c           	      C   s   t t| j}d| |d}g }| |}| d }d}tdD ]V}|| }|dd|d  d	 d
|d  d	 d|d  d	 d|d   d 7 }qB|d	 S )z,Run query through Google Trends with SerpapiZgoogle_jobs)ZengineZapi_keyqZjobs_results    z0
_______________________________________________z
Job Title: title
zCompany Name: Zcompany_namez
Location: locationzDescription: descriptionz1
_______________________________________________
)r   r   r   Zget_secret_valuer   get_dictrange)	selfr   Zserpapi_api_keyparamsZtotal_resultsclientres_striZjobr   r   r   run4   s2    
	zGoogleJobsAPIWrapper.run)r   r   r   __doc__r   __annotations__r   r   r   r   r   r   r   strr+   r   r   r   r   r   	   s   
r   N)r,   typingr   r   r   r   Zlangchain_core.pydantic_v1r   r   r   Zlangchain_core.utilsr	   r
   r   r   r   r   r   <module>   s   