
    h                         d dl mZmZ d dlZd dlmZmZmZ d dl	Z	ddl
mZmZ ddlmZ ddlmZ e dZ G d	 d
e          ZdS )    )ABCabstractmethodN)DictListOptional   )_QUERY1_URL_
_SENTINEL_)YfData)Tickerz/v1/financec                   |   e Zd ZdZdefdefdZedefd            Zedefd            Z	edefd            Z
edefd	            Zedefd
            Zedeej                 fd            Zedeeeef                  fd            ZdefdZddZdefdZdeej                 fdZedd            ZddZdS )Domainz
    Abstract base class representing a domain entity in financial data, with key attributes 
    and methods for fetching and parsing data. Derived classes must implement the `_fetch_and_parse()` method.
    Nkeyc                    || _         || _        t          |          | _        |t          ur6t          j        dt          d           | j                            |           d| _	        d| _
        d| _        d| _        d| _        dS )a  
        Initializes the Domain object with a key, session, and proxy.

        Args:
            key (str): Unique key identifying the domain entity.
            session (Optional[requests.Session]): Session object for HTTP requests. Defaults to None.
        )sessionz=Set proxy via new config function: yf.set_config(proxy=proxy)r   )
stacklevelN)_keyr   r   _datar
   warningswarnDeprecationWarning
_set_proxy_name_symbol	_overview_top_companies_research_reports)selfr   r   proxys       T/var/www/html/marketdash/venv/lib/python3.11/site-packages/yfinance/domain/domain.py__init__zDomain.__init__   s     	#G444

""MY[mz{||||J!!%((($(
&*)-7;AE    returnc                     | j         S )z
        Retrieves the key of the domain entity.

        Returns:
            str: The unique key of the domain entity.
        )r   r   s    r    r   z
Domain.key'   s     yr"   c                 D    |                      | j                   | j        S )z|
        Retrieves the name of the domain entity.

        Returns:
            str: The name of the domain entity.
        )_ensure_fetchedr   r%   s    r    namezDomain.name1   s"     	TZ(((zr"   c                 D    |                      | j                   | j        S )z
        Retrieves the symbol of the domain entity.

        Returns:
            str: The symbol representing the domain entity.
        )r'   r   r%   s    r    symbolzDomain.symbol<   s"     	T\***|r"   c                 ^    |                      | j                   t          | j                  S )z
        Retrieves a Ticker object based on the domain entity's symbol.

        Returns:
            Ticker: A Ticker object associated with the domain entity.
        )r'   r   r   r%   s    r    tickerzDomain.tickerG   s*     	T\***dl###r"   c                 D    |                      | j                   | j        S )z
        Retrieves the overview information of the domain entity.

        Returns:
            Dict: A dictionary containing an overview of the domain entity.
        )r'   r   r%   s    r    overviewzDomain.overviewR   s"     	T^,,,~r"   c                 D    |                      | j                   | j        S )z
        Retrieves the top companies within the domain entity.

        Returns:
            pandas.DataFrame: A DataFrame containing the top companies in the domain.
        )r'   r   r%   s    r    top_companieszDomain.top_companies]   s$     	T0111""r"   c                 D    |                      | j                   | j        S )z
        Retrieves research reports related to the domain entity.

        Returns:
            List[Dict[str, str]]: A list of research reports, where each report is a dictionary with metadata.
        )r'   r   r%   s    r    research_reportszDomain.research_reportsh   s$     	T3444%%r"   c                 L    ddddd}| j                             ||          }|S )z
        Fetches data from the given query URL.

        Args:
            query_url (str): The URL used for the data query.

        Returns:
            Dict: The JSON response data from the request.
        truezen-USUS)	formattedwithReturnslangregion)params)r   get_raw_json)r   	query_urlparams_dictresults       r    _fetchzDomain._fetchs   s5     %+67^bcc((;(GGr"   c                 Z   |                     d          | _        |                     d          | _        |                     |                     di                     | _        |                     |                     di                     | _        |                     d          | _        dS )z
        Parses and assigns common data fields such as name, symbol, overview, and top companies.

        Args:
            data (Dict): The raw data received from the API.
        r(   r*   r.   topCompaniesresearchReportsN)getr   r   _parse_overviewr   _parse_top_companiesr   r   )r   datas     r    _parse_and_assign_commonzDomain._parse_and_assign_common   s     XXf%%
xx))--dhhz2.F.FGG"77QS8T8TUU!%*;!<!<r"   c           
         |                     dd          |                     di                                dd          |                     dd          |                     dd          |                     dd          |                     di                                dd          |                     d	i                                dd          d
S )z
        Parses the overview data for the domain entity.

        Args:
            overview (Dict): The raw overview data.

        Returns:
            Dict: A dictionary containing parsed overview information.
        companiesCountN	marketCaprawmessageBoardIddescriptionindustriesCountmarketWeightemployeeCount)companies_count
market_capmessage_board_idrM   industries_countmarket_weightemployee_countrC   )r   r.   s     r    rD   zDomain._parse_overview   s      (||,<dCC",,{B77;;E4HH (-=t D D#<<t<< (-> E E%\\."==AA%NN&ll?B??CCE4PP
 
 	
r"   c                 |    g d}d |D             }|sdS t          j        ||                              d          S )a)  
        Parses the top companies data and converts it into a pandas DataFrame.

        Args:
            top_companies (Dict): The raw top companies data.

        Returns:
            Optional[pandas.DataFrame]: A DataFrame containing top company data, or None if no data is available.
        )r*   r(   ratingzmarket weightc           	          g | ]i}|                     d           |                     d          |                     d          |                     di                                dd          fjS )r*   r(   rY   rO   rK   NrW   ).0cs     r    
<listcomp>z/Domain._parse_top_companies.<locals>.<listcomp>   s}      b  b  b OP "#x !f !h !nR 8 8 < <U4 H H!J  b  b  br"   N)columnsr*   )_pd	DataFrame	set_index)r   r0   top_companies_columntop_companies_valuess       r    rE   zDomain._parse_top_companies   sn      MLL b  b Ta b  b  b
 $ 	4}1;OPPPZZ[cdddr"   c                      t          d          )z
        Abstract method for fetching and parsing domain-specific data. 
        Must be implemented by derived classes.
        z>_fetch_and_parse() needs to be implemented by children classes)NotImplementedErrorr%   s    r    _fetch_and_parsezDomain._fetch_and_parse   s     ""bcccr"   c                 6    ||                                   dS dS )z
        Ensures that the given attribute is fetched by calling `_fetch_and_parse()` if the attribute is None.

        Args:
            attribute: The attribute to check and potentially fetch.
        N)rf   )r   	attributes     r    r'   zDomain._ensure_fetched   s*     !!##### r"   )r#   N)__name__
__module____qualname____doc__r
   strr!   propertyr   r(   r*   r   r,   r   r.   r   r_   r`   r0   r   r2   r?   rG   rD   rE   r   rf   r'    r"   r    r   r      s        
 *.Z F FC F F F F* S    X c    X     X $ $ $ $ X$ $    X #x6 # # # X# &$tCH~"6 & & & X&4    = = = =
4 
 
 
 
(eXcm5L e e e e* d d d ^d$ $ $ $ $ $r"   r   )abcr   r   pandasr_   typingr   r   r   r   constr	   r
   rF   r   r,   r   _QUERY_URL_r   ro   r"   r    <module>ru      s    # # # # # # # #     ' ' ' ' ' ' ' ' ' '  , , , , , , , ,            ***{$ {$ {$ {$ {$S {$ {$ {$ {$ {$r"   