
    h                         d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZ d dlmZ  G d	 d
e      Z G d de	      Zy)    )IterableOptionalType)CallbackManagerForToolRun)Document)BaseTool)	BaseModelField)	HTTPErrorReadTimeout)ConnectionError)WebBaseLoaderc                   .    e Zd ZU dZ ed      Zeed<   y)YahooFinanceNewsInputz$Input for the YahooFinanceNews tool.zcompany ticker query to look up)descriptionqueryN)__name__
__module____qualname____doc__r
   r   str__annotations__     j/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/tools/yahoo_finance_news.pyr   r      s    .#DEE3Er   r   c                       e Zd ZU dZdZeed<   dZeed<   dZe	ed<   	 e
Zee   ed<   	 dd
edee   defdZedee   d
edefd       Zy	)YahooFinanceNewsToolz3Tool that searches financial news on Yahoo Finance.yahoo_finance_newsnamezUseful for when you need to find financial news about a public company. Input should be a company ticker. For example, AAPL for Apple, MSFT for Microsoft.r   
   top_kargs_schemaNr   run_managerreturnc                    	 ddl }|j                  |      }	 |j                  d| dS 	 g }	 |j                  D cg c]  }|d   d   dk(  r|d   d	   d
    }}|sd| dS t        |      }|j                         }| j                  ||      }	|	sd| dS |	S # t        $ r t        d      w xY w# t        t
        t        f$ r	 d| dcY S w xY wc c}w # t        t
        t        f$ r |sd| dcY S Y w xY w)a  
        Use the Yahoo Finance News tool.

        Args:
            query: Company ticker symbol (e.g., 'AAPL' for Apple).
            run_manager: Optional callback manager.

        Returns:
            str: Formatted news results or error message.
        r   NzXCould not import yfinance python package. Please install it with `pip install yfinance`.zCompany ticker z not found.contentcontentTypeSTORYcanonicalUrlurlz-No news found for company that searched with z ticker.)	web_paths)yfinanceImportErrorTickerisinr   r   r   newsr   load_format_results)
selfr   r#   r,   companylinksnloaderdocsresults
             r   _runzYahooFinanceNewsTool._run"   s]   	 //%(	8||#({;; $
 	W !Y<.'9 )^,U3E  B5'RR/{{}%%dE2B5'RR;  	A 	 ;8 	8$UG;77	8

 ;8 	WFugXVV 	Ws>   B B3 C CC B03CCC C98C9r8   c           
         | D cg c]k  }||j                   j                  dd      v s||j                   d   v r:dj                  |j                   d   |j                   j                  dd      g      m }}dj                  |      S c c}w )Nr    title
z

)metadatagetjoin)r8   r   docdoc_stringss       r   r2   z$YahooFinanceNewsTool._format_resultsR   s     
((;;W-- IIs||G,cll.>.>}b.QRS
 
 {{;''
s   A0B)N)r   r   r   r   r   r   r   r   r!   intr   r"   r   r	   r   r   r:   staticmethodr   r   r2   r   r   r   r   r      s    =$D#$	;   E3O*#8Ki8
 <@.. 78. 
	.` (hx0 ( ( ( (r   r   N)typingr   r   r   langchain_core.callbacksr   langchain_core.documentsr   langchain_core.toolsr   pydanticr	   r
   requests.exceptionsr   r   urllib3.exceptionsr   -langchain_community.document_loaders.web_baser   r   r   r   r   r   <module>rN      s<    + + > - ) % 6 . GFI FG(8 G(r   