
    dh9                     ^    S r SSKJrJrJrJr  SSKJrJr  SSK	J
r
JrJrJr   " S S\
5      rg)z&Util that calls Google Finance Search.    )AnyDictOptionalcast)convert_to_secret_strget_from_dict_or_env)	BaseModel
ConfigDict	SecretStrmodel_validatorc                       \ rS rSr% SrSr\\S'   Sr\	\
   \S'   \" SS9r\" SS	9\S
\S\4S j5       5       rS\S\4S jrSrg)GoogleFinanceAPIWrapper	   a0  Wrapper for SerpApi's Google Finance 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 GoogleFinanceAPIWrapper
    google_Finance = GoogleFinanceAPIWrapper()
    google_Finance.run('langchain')
Nserp_search_engineserp_api_keyforbid)extrabefore)modevaluesreturnc                     [        [        USS5      5      US'    SSKJn  UnX1S'   U$ ! [         a    [	        S5      ef = f)z?Validate that api key and python package exists in environment.r   SERPAPI_API_KEYr   )SerpApiClientzigoogle-search-results is not installed. Please install it with `pip install google-search-results>=2.4.2`r   )r   r   serpapir   ImportError)clsr   r   r   s       d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/google_finance.pyvalidate_environment,GoogleFinanceAPIWrapper.validate_environment    sa     "7 9JK"
~	- +'9#$  	 	s   ) ?queryc                 P   [        [        U R                  5      nSUR                  5       US.n0 nU R	                  U5      nUR                  5       nU(       d  SU-   $ UR                  S0 5      nSU-   S-   nSU;   aM  UR                  S/ 5      S   nUS	   n	US
   n
US   nUS   nUS   nUSU	 S3SU
 S3-   SU S3-   SU S3-   -  nOUS-  nU HP  nUS:X  d  US:X  d  US:X  d  M  X~-  nUS-  nU[        Xn   S   S
   5      -  nUS-  nXvU   S   S   S   -  nUS-  nMR     U$ )z-Run query through Google Finance with Serpapigoogle_finance)engineapi_keyqz"Nothing was found from the query: marketsz
Query: 
futures_chainr   stockpriceprice_movement
percentagemovementzstock: zprice: zpercentage: z
movement: zNo summary information
usasiaeuropez
: price = z, movement = )r   r   r   get_secret_valuer   get_dictgetstr)selfr!   serpapi_api_keyparamstotal_resultsclientr'   resr)   r*   r+   tempr-   r.   keys                  r   runGoogleFinanceAPIWrapper.run6   s   y$*;*;<&&779
 ((0)7%??##Ir2E!D(m+)--orB1EM!'*E!'*E !12Dl+JJ'H%#E7"%& B/0 xj+,C --CCtC8O
|#s7<?7344&s|A'78DDt  
     )__name__
__module____qualname____firstlineno____doc__r   r   __annotations__r   r   r   r
   model_configr   classmethodr   r   r5   r>   __static_attributes__rA   r@   r   r   r   	   sr     #"(,L(9%,L (#$ 3   $(- - -r@   r   N)rF   typingr   r   r   r   langchain_core.utilsr   r   pydanticr	   r
   r   r   r   rA   r@   r   <module>rN      s%    , , , L F FZi Zr@   