
    U>qj6                     \    d dl ZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ  G d d	      Zy)
    N   )utils)YfConfig)
_BASE_URL_)YfData)YFDataExceptionc                       e Zd Z	 	 	 ddZddZedd       Zedd       Zedd       Zedd       Z	edd       Z
edd	       Zedd
       Zy)SearchNc                    || _         t        | j                         | _        || _        || _        |	| _        || _        || _        || _        || _	        || _
        || _        || _        || _        |
| _        t        j                          | _        i | _        i | _        g | _        g | _        g | _        g | _        g | _        | j3                          y)a6  
        Fetches and organizes search results from Yahoo Finance, including stock quotes and news articles.

        Args:
            query: The search query (ticker symbol or company name).
            max_results: Maximum number of stock quotes to return (default 8).
            news_count: Number of news articles to include (default 8).
            lists_count: Number of lists to include (default 8).
            include_cb: Include the company breakdown (default True).
            include_nav_links: Include the navigation links (default False).
            include_research: Include the research reports (default False).
            include_cultural_assets: Include the cultural assets (default False).
            enable_fuzzy_query: Enable fuzzy search for typos (default False).
            recommended: Recommended number of results to return (default 8).
            session: Custom HTTP session for requests (default None).
            timeout: Request timeout in seconds (default 30).
            raise_errors: Raise exceptions on error (default True).
        )sessionN)r   r   _dataquerymax_resultsenable_fuzzy_query
news_counttimeoutraise_errorslists_count
include_cb	nav_linksenable_researchenable_cultural_assetsrecommendedr   get_yf_logger_logger	_response_all_quotes_news_lists	_research_navsearch)selfr   r   r   r   r   include_nav_linksinclude_researchinclude_cultural_assetsr   r   r   r   r   s                 N/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/yfinance/search.py__init__zSearch.__init__    s    * DLL1

&"4$(&$*/&=#&**,	
	    c                 ~   t          d}| j                  | j                  | j                  | j                  dd| j
                  | j                  | j                  | j                  | j                  | j                  d}| j                  j                  | j                   dt        t        |                    | j                  j!                  ||| j"                        }|d|j$                  v rt'        d      	 |j)                         }|| _        |j7                  d
g       D cg c]	  }d|v s| c}| _        |j7                  dg       | _        |j7                  dg       | _        |j7                  dg       | _        |j7                  dg       | _         | j8                  | j:                  | j<                  | j>                  | j@                  d| _!        | S # t*        j,                  $ rI t.        j                  j0                  s | j                  j3                  | j                   d	       i }Y )w xY wc c}w )z=Search using the query parameters defined in the constructor.z/v1/finance/searchtss_match_phrase_querynews_cie_vespa)qquotesCountenableFuzzyQuery	newsCountquotesQueryIdnewsQueryId
listsCountenableCbenableNavLinksenableResearchReportsenableCulturalAssetsrecommendedCountz: Yahoo GET parameters: )urlparamsr   zWill be right backz)*** YAHOO! FINANCE IS CURRENTLY DOWN! ***z%: 'search' fetch received faulty dataquotessymbolnewslistsresearchReportsnav)r<   r>   r?   researchrA   )"r   r   r   r   r   r   r   r   r   r   r   r   debugstrdictr   	cache_getr   textr   json_jsonJSONDecodeErrorr   hide_exceptionserrorr   getr   r   r    r!   r"   r   )r$   r:   r;   dataquotes        r(   r#   zSearch.searchR   s   ./++ $ 7 75+**"nn%)%9%9$($?$? $ 0 0
 	djj\)A#d6lBSATUVzz##FDLL#Q</499<!"MNN	99;D +/88Hb+AW%XQVEVWXXfb)
hhw+"3R8HHUB'	#||TZZ$++cgcqcq II'	 # $$ 	>>11LL$**-RSTD		 Xs   =G (	H:2H:AH76H7c                     | j                   S )z'Get the quotes from the search results.)r   r$   s    r(   r<   zSearch.quotes~   s     ||r*   c                     | j                   S )z%Get the news from the search results.)r   rQ   s    r(   r>   zSearch.news   s     zzr*   c                     | j                   S )z&Get the lists from the search results.)r    rQ   s    r(   r?   zSearch.lists   s     {{r*   c                     | j                   S )z1Get the research reports from the search results.)r!   rQ   s    r(   rB   zSearch.research        ~~r*   c                     | j                   S )z1Get the navigation links from the search results.)r"   rQ   s    r(   rA   z
Search.nav        yyr*   c                     | j                   S )zOGet all the results from the search results: filtered down version of response.)r   rQ   s    r(   allz
Search.all   rW   r*   c                     | j                   S )z-Get the raw response from the search results.)r   rQ   s    r(   responsezSearch.response   rU   r*   )   r\   r\   TFFFFr\   N   T)returnr
   )r^   list)r^   zdict[str,list])r^   rE   )__name__
__module____qualname__r)   r#   propertyr<   r>   r?   rB   rA   rY   r[    r*   r(   r
   r
      s    mrno8<0d*X              r*   r
   )rH   rI    r   configr   constr   rN   r   
exceptionsr   r
   rd   r*   r(   <module>ri      s%   ,      '@ @r*   