
    Wg                     D    d dl ZddlmZ ddlmZ ddlmZ  G d d      Zy)    N   )utils)
_BASE_URL_)YfDatac                       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 | _        | j5                          y)au  
        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).
            proxy: Proxy settings for requests (default None).
            timeout: Request timeout in seconds (default 30).
            raise_errors: Raise exceptions on error (default True).
        )sessionN)querymax_resultsenable_fuzzy_query
news_countr
   proxytimeoutraise_errorslists_count
include_cb	nav_linksenable_researchenable_cultural_assetsrecommendedr   _datar   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   r   s                  B/var/www/html/venv/lib/python3.12/site-packages/yfinance/search.py__init__zSearch.__init__   s    , 
&"4$
(&$*/&=#&DLL1
**,	
	    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"                  | j$                        }|d|j&                  v rt)        d      	 |j+                         }|| _        |j5                  d
g       D cg c]	  }d|v s| c}| _        |j5                  dg       | _        |j5                  dg       | _        |j5                  dg       | _        |j5                  dg       | _        | j6                  | j8                  | j:                  | j<                  | j>                  d| _         | S # t,        j.                  $ r. | j                  j1                  | 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   r   zWill be right backz~*** YAHOO! FINANCE IS CURRENTLY DOWN! ***
Our engineers are working quickly to resolve the issue. Thank you for your patience.zI: Failed to retrieve search results and received faulty response instead.quotessymbolnewslistsresearchReportsnav)r;   r=   r>   researchr@   )!r   r   r   r   r   r   r   r   r   r   r   r   debugstrdictr   	cache_getr   r   textRuntimeErrorjson_jsonJSONDecodeErrorerrorr   getr   r   r   r    r!   r   )r#   r9   r:   dataquotes        r'   r"   zSearch.searchQ   s   ./++ $ 7 75+**"nn%)%9%9$($?$? $ 0 0
 	djj\)A#d6lBSATUVzz##F$**VZVbVb#c</499<  I J J	99;D
 +/88Hb+AW%XQVEVWXXfb)
hhw+"3R8HHUB'	#||TZZ$++cgcqcq II'	  $$ 	LL$**-vwxD	 Xs   G& 3	H*=H*&=H'&H'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   rP   s    r'   r=   zSearch.news   s     zzr)   c                     | j                   S )z&Get the lists from the search results.)r   rP   s    r'   r>   zSearch.lists   s     {{r)   c                     | j                   S )z1Get the research reports from the search results.)r    rP   s    r'   rA   zSearch.research        ~~r)   c                     | j                   S )z1Get the navigation links from the search results.)r!   rP   s    r'   r@   z
Search.nav        yyr)   c                     | j                   S )zOGet all the results from the search results: filtered down version of response.)r   rP   s    r'   allz
Search.all   rV   r)   c                     | j                   S )z-Get the raw response from the search results.)r   rP   s    r'   responsezSearch.response   rT   r)   )   r[   r[   TFFFFr[   NN   T)returnr   )r]   list)r]   zdict[str,list])r]   rD   )__name__
__module____qualname__r(   r"   propertyr;   r=   r>   rA   r@   rX   rZ    r)   r'   r   r      s    mrnoDH1f*X              r)   r   )	rH   rI    r   constr   rM   r   r   rc   r)   r'   <module>rf      s   ,    A Ar)   