
    dh                         S SK JrJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKJrJr  S SKJr  S SKJr   " S	 S
\5      r " S S\	5      rg)    )IterableOptionalType)CallbackManagerForToolRun)Document)BaseTool)	BaseModelField)	HTTPErrorReadTimeout)ConnectionError)WebBaseLoaderc                   0    \ rS rSr% Sr\" SS9r\\S'   Sr	g)YahooFinanceNewsInput   z$Input for the YahooFinanceNews tool.zcompany ticker query to look up)descriptionquery N)
__name__
__module____qualname____firstlineno____doc__r
   r   str__annotations____static_attributes__r       d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/yahoo_finance_news.pyr   r      s    .#DEE3Er   r   c                       \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\
\S'    \r\\   \S	'    SS\S\\   S\4S jjr\S\\   S\S\4S j5       rSrg
)YahooFinanceNewsTool   z3Tool 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                      SSK nUR                  U5      n UR                  c  SU S3$  / n UR                   Vs/ sH  nUS   S   S:X  d  M  US   S	   S
   PM     nnU(       d  SU S3$ [        US9nUR                  5       nU R                  X5      n	U	(       d  SU S3$ U	$ ! [         a    [        S5      ef = f! [        [
        [        4 a	    SU S3s $ f = fs  snf ! [        [
        [        4 a    U(       d  SU S3s $  Nf = f)z
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'   r0   companylinksnloaderdocsresults
             r   _runYahooFinanceNewsTool._run"   s`   	 //%(	8||#({;; $
 	W !%AY<.'9 4)^,U3%   B5'RR/{{}%%d2B5'RR;  	A 	 ;8 	8$UG;77	8

 ;8 	WFugXVV 	WsD   B' C  C& C!C!C& 'B= CC!C& &"DDr<   c           
      &   U  Vs/ sHp  nXR                   R                  SS5      ;   d  XR                   S   ;   d  M6  SR                  UR                   S   UR                   R                  SS5      /5      PMr     nnSR                  U5      $ s  snf )Nr    title
z

)metadatagetjoin)r<   r   docdoc_stringss       r   r6   $YahooFinanceNewsTool._format_resultsR   s     
((;;W-- TDIIs||G,cll.>.>}b.QRS 	 
 {{;''
s
   4B>Br   )N)r   r   r   r   r   r#   r   r   r   r%   intr   r&   r   r	   r   r   r>   staticmethodr   r   r6   r   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>rT      s<    + + > - ) % 6 . GFI FG(8 G(r   