
    Ej6                     d    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dS )
    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dS )Search   TFN   c                    || _         t          | j                   | _        || _        || _        |	| _        || _        || _        || _        || _	        || _
        || _        || _        || _        |
| _        t          j                    | _        i | _        i | _        g | _        g | _        g | _        g | _        g | _        |                                  dS )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                 K/var/www/html/bolsaweb/venv/lib/python3.11/site-packages/yfinance/search.py__init__zSearch.__init__    s    * DL111

&"4$(&$*/&=#&*,,	
	    returnc                    t            d}| j        | j        | j        | j        dd| j        | j        | j        | j        | j	        | j
        d}| j                            | j         dt          t          |                                | j                            ||| j                  }|	d|j        v rt'          d	          	 |                                }nK# t*          j        $ r9 t.          j        j        s | j                            | j         d
           i }Y nw xY w|| _        d |                    dg           D             | _        |                    dg           | _        |                    dg           | _        |                    dg           | _        |                    dg           | _         | j        | j        | j        | j        | j         d| _!        | S )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   NzWill be right backz)*** YAHOO! FINANCE IS CURRENTLY DOWN! ***z%: 'search' fetch received faulty datac                     g | ]}d |v |	S )symbol ).0quotes     r*   
<listcomp>z!Search.search.<locals>.<listcomp>s   s#    WWW%XQVEVEVEVEVEVr,   quotesnewslistsresearchReportsnav)rE   rF   rG   researchrI   )"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>   datas       r*   r%   zSearch.searchR   s   ///+ $ 75+*"n%)%9$($? $ 0
 
 	djUU#d6llBSBSUUVVVz##FDL#QQ</49<<!"MNNN	99;;DD$ 	 	 	>1 L$*SSSTTTDDD		 WW488Hb+A+AWWWXXfb))
hhw++"3R88HHUB''	#|TZ$+cgcq I' '	 s   C AD$#D$listc                     | j         S )z'Get the quotes from the search results.)r    r&   s    r*   rE   zSearch.quotes~   s     |r,   c                     | j         S )z%Get the news from the search results.)r!   rY   s    r*   rF   zSearch.news   s     zr,   c                     | j         S )z&Get the lists from the search results.)r"   rY   s    r*   rG   zSearch.lists   s     {r,   c                     | j         S )z1Get the research reports from the search results.)r#   rY   s    r*   rJ   zSearch.research        ~r,   c                     | j         S )z1Get the navigation links from the search results.)r$   rY   s    r*   rI   z
Search.nav        yr,   dict[str,list]c                     | j         S )zOGet all the results from the search results: filtered down version of response.)r   rY   s    r*   allz
Search.all   r_   r,   rM   c                     | j         S )z-Get the raw response from the search results.)r   rY   s    r*   responsezSearch.response   r]   r,   )r   r   r   TFFFFr   Nr   T)r-   r
   )r-   rW   )r-   r`   )r-   rM   )__name__
__module____qualname__r+   r%   propertyrE   rF   rG   rJ   rI   rb   rd   rA   r,   r*   r
   r
      s'       mrno8<0 0 0 0d* * * *X    X    X    X    X    X    X    X  r,   r
   )rP   rQ    r   configr   constr   rV   r   
exceptionsr   r
   rA   r,   r*   <module>rm      s   ,                             ' ' ' ' ' '@ @ @ @ @ @ @ @ @ @r,   