
    hA                     8   d dl mZ d dlZd dlZd dlmZmZ d dlm	Z
 d dlZd dlZd dlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZm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$m%Z% ddl&m'Z' ddl(m)Z) ddlm*Z*m+Z+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1 d a2 G d d          Z3dS )    )print_functionN)OptionalUnion)quote)requests   )utilscache)_MIC_TO_YAHOO_SUFFIX)YfData)YFEarningsDateMissingYFRateLimitError)	WebSocket)Analysis)Fundamentals)Holders)QuoteFastInfo)PriceHistory)	FundsData)
_BASE_URL_
_ROOT_URL__QUERY1_URL_
_SENTINEL_)StringIO)BeautifulSoupc                      e Zd ZdefdZej        dej        fd            Z	d Z
d Zej        d             Zedfd	Zedfd
ZedfdZefdefdZefdefdZedfdZedfdZedfdZedfdZedfdZedfdZefdefdZefdZedfdZefdefdZedfdZedfdZedfdZedfdZ edfdZ!edfdZ"eddfdZ#edddfd Z$edddfd!Z%edddfd"Z&edddfd#Z'edddfd$Z(edddfde)ej        ef         fd%Z*edddfd&Z+ed'fdej,        fd(Z-ed'fdej,        fd)Z.ed'fdej,        fd*Z/ed'fdej,        fd+Z0edfde)ej        ef         fd,Z1ej        ddefd-            Z2efde3e4         fd.Z5d/d0efde6fd1Z7d;de3ej                 fd4Z8ej        d;de3ej                 fd5            Z9ej        d2efde3ej                 fd6            Z:efdefd7Z;efde3e<         fd8Z=d<d:Z>dS )=
TickerBaseNc                    t          |t                    rt          |          dk    rt          d          |\  }}|                    d          r
|dd         }|                                t          vrt          d| d          t          |                                         }|dk    r| d| }n|}|                                | _        |pt          j	        d	
          | _
        d| _        d| _        g | _        d| _        i | _        d| _        d| _        | j        dk    rt          d          t%          |          | _        |t(          ur6t+          j        dt.          d           | j                            |           t3          j        | j                  r| j        }t7          j                    }|                    |          | _        | j        st3          j        |          | _        | j        dk    rt          d|           | j        r|                    || j                   d| _         tC          | j        | j                  | _"        tG          | j        | j                  | _$        tK          | j        | j                  | _&        tO          | j        | j                  | _(        d| _)        d| _*        d| _+        d| _,        dS )as  
        Initialize a Yahoo Finance Ticker object.

        Args:
            ticker (str | tuple[str, str]):
                Yahoo Finance symbol (e.g. "AAPL")
                or a tuple of (symbol, MIC) e.g. ('OR','XPAR')
                (MIC = market identifier code)

            session (requests.Session, optional):
                Custom requests session.
           z'Ticker tuple must be (symbol, mic_code).r   NzUnknown MIC code: '' chrome)impersonatezEmpty ticker name)session=Set proxy via new config function: yf.set_config(proxy=proxy)
stacklevelzInvalid ISIN number: )-
isinstancetuplelen
ValueError
startswithupperr   tickerr   Sessionr&   _tz_isin_news_shares_earnings_dates	_earnings_financialsr   _datar   warningswarnDeprecationWarning
_set_proxyr	   is_isinr
   get_isin_cachelookupget_ticker_by_isinstore_price_historyr   	_analysisr   _holdersr   _quoter   _fundamentals_funds_data
_fast_info_message_handlerws)	selfr0   r&   proxybase_symbolmic_codesfxisincs	            K/var/www/html/marketdash/venv/lib/python3.11/site-packages/yfinance/base.py__init__zTickerBase.__init__7   s    fe$$ 	%6{{a !JKKK$*!K""3'' (#ABB<~~';;; !Bx!B!B!BCCC&x~~'7'78Cbyy'//#//$llnnH("2x"H"H"H

! ;"0111#G444

""MY[mz{||||J!!%((( =%% 		+;D$&&A((4..DK; =#6t<<{b   !?!?!?@@@{ +dk*** #!$*dk::
DK88DJ44)$*dkBB $    returnc                 @     |                                  j        |i |S N)_lazy_load_price_historyhistory)rL   argskwargss      rS   rZ   zTickerBase.history   s&    6t,,..6GGGGrU   c                     | j         4t          | j        | j        |                     d                    | _         | j         S )N
   timeout)rC   r   r9   r0   _get_ticker_tz)rL   s    rS   rY   z#TickerBase._lazy_load_price_history   s>    &".tz4;H[H[dfH[HgHg"h"hD""rU   c                    | j         | j         S t          j                    }|                    | j                  }|r1t          j        |          s|                    | j        d            d }|{|                     |          }|2t          dk     r't          dz  a	dD ]}|| j
        v r| j
        |         } nt          j        |          r|                    | j        |           nd }|| _         |S )Nr    r   )exchangeTimezoneNametimeZoneFullName)r2   r
   get_tz_cacher@   r0   r	   is_valid_timezonerB   _fetch_ticker_tz_tz_info_fetch_ctrinfo)rL   r`   rR   tzks        rS   ra   zTickerBase._get_ticker_tz   s   88O  XXdk"" 	e-b11 	GGDK&&&B:&&w//Bz &)) '!+&I " "	>>!%1B!E * &r** R((((	rU   c                 8   t          j                    }ddd}t           d| j         }	 | j                            |||          }|                                }|                    di                               dd           }|r!|                    d| j         d|            n	 |d         d	         d
         d         d         S # t          $ r}|
                    d| j         d|            |                    d           |                    d           |                    d|            |                    d           Y d }~nJd }~ww xY w# t          $ r  t          $ r+}|
                    d| j         d|            Y d }~d S d }~ww xY wd S )N1d)rangeintervalz/v8/finance/chart/)urlparamsr`   charterrorz$Got error from yahoo api for ticker z	, Error: resultr   metarc   z/Could not get exchangeTimezoneName for ticker 'z
' reason: zGot response: z------------- zFailed to get ticker ')r	   get_yf_loggerr   r0   r9   	cache_getjsongetdebug	Exceptionrs   r   )	rL   r`   loggerrq   rp   datars   erres	            rS   rg   zTickerBase._fetch_ticker_tz   s    $&&T22 <<t{<<	2:''C'PPD99;;D HHWb))--gt<<E 2aDKaaZ_aabbbb2=215f=>TUU  2 2 2LL!oSWS^!o!ojm!o!opppLL!1222LL111LLT,,,LL111111112   	 	 	 	 	 	LLL$+LLLLMMM44444	" ts0   1E *C
 

EA7EEF, FFFc                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                S |S )z~
        Returns a DataFrame with the recommendations
        Columns: period  strongBuy  buy  hold  sell  strongSell
        r'   r    r(   )	r   r:   r;   r<   r9   r=   rF   recommendationsto_dictrL   rM   as_dictr~   s       rS   get_recommendationszTickerBase.get_recommendations   sd    
 
""MY[mz{||||J!!%((({* 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           |                     |          S )Nr'   r    r(   )r   )r   r:   r;   r<   r9   r=   r   )rL   rM   r   s      rS   get_recommendations_summaryz&TickerBase.get_recommendations_summary   sT    
""MY[mz{||||J!!%((('''888rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                S |S )z
        Returns a DataFrame with the recommendations changes (upgrades/downgrades)
        Index: date of grade
        Columns: firm toGrade fromGrade action
        r'   r    r(   )	r   r:   r;   r<   r9   r=   rF   upgrades_downgradesr   r   s       rS   get_upgrades_downgradesz"TickerBase.get_upgrades_downgrades   sd     
""MY[mz{||||J!!%((({. 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        S Nr'   r    r(   )r   r:   r;   r<   r9   r=   rF   calendarrL   rM   s     rS   get_calendarzTickerBase.get_calendar   sH    
""MY[mz{||||J!!%((({##rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        S r   )r   r:   r;   r<   r9   r=   rF   sec_filingsr   s     rS   get_sec_filingszTickerBase.get_sec_filings   sH    
""MY[mz{||||J!!%((({&&rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                S |S r   )	r   r:   r;   r<   r9   r=   rE   majorr   r   s       rS   get_major_holderszTickerBase.get_major_holders  sb    
""MY[mz{||||J!!%(((}" 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }||r|                                S |S d S r   )	r   r:   r;   r<   r9   r=   rE   institutionalr   r   s       rS   get_institutional_holdersz$TickerBase.get_institutional_holders  sp    
""MY[mz{||||J!!%(((}* &||~~%K rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }||r|                                S |S d S r   )	r   r:   r;   r<   r9   r=   rE   
mutualfundr   r   s       rS   get_mutualfund_holdersz!TickerBase.get_mutualfund_holders  sp    
""MY[mz{||||J!!%(((}' &||~~%K rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }||r|                                S |S d S r   )	r   r:   r;   r<   r9   r=   rE   insider_purchasesr   r   s       rS   get_insider_purchasesz TickerBase.get_insider_purchases#  sp    
""MY[mz{||||J!!%(((}. &||~~%K rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }||r|                                S |S d S r   )	r   r:   r;   r<   r9   r=   rE   insider_transactionsr   r   s       rS   get_insider_transactionsz#TickerBase.get_insider_transactions.  sp    
""MY[mz{||||J!!%(((}1 &||~~%K rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }||r|                                S |S d S r   )	r   r:   r;   r<   r9   r=   rE   insider_rosterr   r   s       rS   get_insider_roster_holdersz%TickerBase.get_insider_roster_holders9  sp    
""MY[mz{||||J!!%(((}+ &||~~%K rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|S r   )r   r:   r;   r<   r9   r=   rF   ri   rL   rM   r~   s      rS   get_infozTickerBase.get_infoD  sL    
""MY[mz{||||J!!%((({rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        t          |           | _        | j        S r   )r   r:   r;   r<   r9   r=   rI   r   r   s     rS   get_fast_infozTickerBase.get_fast_infoL  sZ    
""MY[mz{||||J!!%(((?"&tnnDOrU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                S |S r   )	r   r:   r;   r<   r9   r=   rF   sustainabilityr   r   s       rS   get_sustainabilityzTickerBase.get_sustainabilityU  sb    
""MY[mz{||||J!!%((({) 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           	 | j        j        }|S r   )r   r:   r;   r<   r9   r=   rD   analyst_price_targetsr   s      rS   get_analyst_price_targetsz$TickerBase.get_analyst_price_targets_  sS    
""MY[mz{||||J!!%(((	 ~3rU   c                     |t           ur6t          j        dt          d           | j                            |           	 | j        j        }|r|                                n|S r   )	r   r:   r;   r<   r9   r=   rD   earnings_estimater   r   s       rS   get_earnings_estimatez TickerBase.get_earnings_estimatej  se    
""MY[mz{||||J!!%(((	 ~/!(2t||~~~d2rU   c                     |t           ur6t          j        dt          d           | j                            |           	 | j        j        }|r|                                n|S r   )	r   r:   r;   r<   r9   r=   rD   revenue_estimater   r   s       rS   get_revenue_estimatezTickerBase.get_revenue_estimatev  e    
""MY[mz{||||J!!%(((	 ~.!(2t||~~~d2rU   c                     |t           ur6t          j        dt          d           | j                            |           	 | j        j        }|r|                                n|S r   )	r   r:   r;   r<   r9   r=   rD   earnings_historyr   r   s       rS   get_earnings_historyzTickerBase.get_earnings_history  r   rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                n|S )zu
        Index:      0q  +1q  0y  +1y
        Columns:    current  7daysAgo  30daysAgo  60daysAgo  90daysAgo
        r'   r    r(   )	r   r:   r;   r<   r9   r=   rD   	eps_trendr   r   s       rS   get_eps_trendzTickerBase.get_eps_trend  s`    
 
""MY[mz{||||J!!%(((~'!(2t||~~~d2rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                n|S )z{
        Index:      0q  +1q  0y  +1y
        Columns:    upLast7days  upLast30days  downLast7days  downLast30days
        r'   r    r(   )	r   r:   r;   r<   r9   r=   rD   eps_revisionsr   r   s       rS   get_eps_revisionszTickerBase.get_eps_revisions  s`    
 
""MY[mz{||||J!!%(((~+!(2t||~~~d2rU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                n|S )zi
        Index:      0q  +1q  0y  +1y +5y -5y
        Columns:    stock  industry  sector  index
        r'   r    r(   )	r   r:   r;   r<   r9   r=   rD   growth_estimatesr   r   s       rS   get_growth_estimateszTickerBase.get_growth_estimates  s`    
 
""MY[mz{||||J!!%(((~.!(2t||~~~d2rU   yearlyc                 *   |t           ur6t          j        dt          d           | j                            |           | j        j        dS | j        j        |         }|r1|                                }d| j	        vrdn| j	        d         |d<   |S |S )z
        :Parameters:
            as_dict: bool
                Return table as Python dict
                Default is False
            freq: str
                "yearly" or "quarterly" or "trailing"
                Default is "yearly"
        r'   r    r(   NfinancialCurrencyUSD)
r   r:   r;   r<   r9   r=   rG   earningsr   r7   )rL   rM   r   freqr~   	dict_datas         rS   get_earningszTickerBase.get_earnings  s     
""MY[mz{||||J!!%(((&.4!*40 	I6IQUQ_6_6_UUeies#f%I)*rU   c                 b   |t           ur6t          j        dt          d           | j                            |           | j        j                            |          }|r7|	                                }t          j        |j        dg d          |_        |r|                                S |S )ag  
        :Parameters:
            as_dict: bool
                Return table as Python dict
                Default is False
            pretty: bool
                Format row names nicely for readability
                Default is False
            freq: str
                "yearly" or "quarterly" or "trailing"
                Default is "yearly"
        r'   r    r(   r   rv   )EBITEBITDAEPSNIsepacronyms)r   r:   r;   r<   r9   r=   rG   
financialsget_income_time_seriescopyr	   camel2titleindexr   rL   rM   r   prettyr   r~   s         rS   get_income_stmtzTickerBase.get_income_stmt  s     
""MY[mz{||||J!!%(((!,CCCNN 	j99;;D*4:3IhIhIhiiiDJ 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           |                     ||||          S r   r   r:   r;   r<   r9   r=   r   rL   rM   r   r   r   s        rS   get_incomestmtzTickerBase.get_incomestmt  W    
""MY[mz{||||J!!%(((##E7FDAAArU   c                     |t           ur6t          j        dt          d           | j                            |           |                     ||||          S r   r   r   s        rS   get_financialszTickerBase.get_financials  r   rU   c                 `   |t           ur6t          j        dt          d           | j                            |           | j        j                            |          }|r6|	                                }t          j        |j        ddg          |_        |r|                                S |S aY  
        :Parameters:
            as_dict: bool
                Return table as Python dict
                Default is False
            pretty: bool
                Format row names nicely for readability
                Default is False
            freq: str
                "yearly" or "quarterly"
                Default is "yearly"
        r'   r    r(   r   rv   PPEr   )r   r:   r;   r<   r9   r=   rG   r   get_balance_sheet_time_seriesr   r	   r   r   r   r   s         rS   get_balance_sheetzTickerBase.get_balance_sheet  s     
""MY[mz{||||J!!%((( !,JJPTJUU 	R99;;D*4:3%QQQDJ 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           |                     ||||          S r   )r   r:   r;   r<   r9   r=   r   r   s        rS   get_balancesheetzTickerBase.get_balancesheet  sW    
""MY[mz{||||J!!%(((%%eWfdCCCrU   c                 `   |t           ur6t          j        dt          d           | j                            |           | j        j                            |          }|r6|	                                }t          j        |j        ddg          |_        |r|                                S |S r   )r   r:   r;   r<   r9   r=   rG   r   get_cash_flow_time_seriesr   r	   r   r   r   r   s         rS   get_cash_flowzTickerBase.get_cash_flow  s     
""MY[mz{||||J!!%((( !,FFDFQQ 	R99;;D*4:3%QQQDJ 	"<<>>!rU   c                     |t           ur6t          j        dt          d           | j                            |           |                     ||||          S r   )r   r:   r;   r<   r9   r=   r   r   s        rS   get_cashflowzTickerBase.get_cashflow/  sW    
""MY[mz{||||J!!%(((!!%&$???rU   maxc                     |t           ur6t          j        dt          d           | j                            |           |                                                     |          S Nr'   r    r(   )period)r   r:   r;   r<   r9   r=   rY   get_dividendsrL   rM   r   s      rS   r   zTickerBase.get_dividends5  s`    
""MY[mz{||||J!!%(((,,..<<F<KKKrU   c                     |t           ur6t          j        dt          d           | j                            |           |                                                     |          S r   )r   r:   r;   r<   r9   r=   rY   get_capital_gainsr   s      rS   r   zTickerBase.get_capital_gains;  s`    
""MY[mz{||||J!!%(((,,..@@@OOOrU   c                     |t           ur6t          j        dt          d           | j                            |           |                                                     |          S r   )r   r:   r;   r<   r9   r=   rY   
get_splitsr   s      rS   r   zTickerBase.get_splitsA  s`    
""MY[mz{||||J!!%(((,,..999HHHrU   c                     |t           ur6t          j        dt          d           | j                            |           |                                                     |          S r   )r   r:   r;   r<   r9   r=   rY   get_actionsr   s      rS   r   zTickerBase.get_actionsG  s`    
""MY[mz{||||J!!%(((,,..::&:IIIrU   c                     |t           ur6t          j        dt          d           | j                            |           | j        j        }|r|                                S |S r   )	r   r:   r;   r<   r9   r=   rG   sharesr   r   s       rS   
get_shareszTickerBase.get_sharesM  sc    
""MY[mz{||||J!!%(((!( 	"<<>>!rU   c                 &   t          j                    }|t          ur6t          j        dt
          d           | j                            |           |                     d          }t          j
                                                            |          }|t          j        ||          }|t          j        ||          }||}||t          j        d          z
  }||k    r|                    d           d S |                    d	          }|                    d	          }d
| j         d| j         }| dt'          |                                           dt'          |                                           }	 | j                            |          }	|	                                }	nD# t.          j        t2          j        j        f$ r! |                    | j         d           Y d S w xY w	 |	d         d         d         dk    }
n# t8          $ r d}
Y nw xY w|
r|                    | j         d           d S |	d         d         }d|d         vrd S 	 t          j        |d         d         t          j        |d         d         d                    }n7# t>          $ r*}|                    | j         d|            Y d }~d S d }~ww xY w|j         !                    |          |_         |"                                }|S )Nr'   r    r(   r^   r_   i$  )dayszStart date must be before endDzRhttps://query2.finance.yahoo.com/ws/fundamentals-timeseries/v1/finance/timeseries/z?symbol=z	&period1=z	&period2=rp   z*: Yahoo web request for share count failedfinancers   codezBad RequestF
timeseriesrt   
shares_outr   	timestamps)unit)r   z%: Failed to parse shares count data: )#r	   rw   r   r:   r;   r<   r9   r=   ra   pd	Timestamputcnow
tz_convert_parse_user_dt	Timedeltars   floorceilr0   intr  rx   ry   _jsonJSONDecodeErrorr   
exceptionsRequestExceptionKeyErrorSeriesto_datetimer|   r   tz_localize
sort_index)rL   startendrM   r}   rj   dt_nowts_url_base
shares_url	json_datafailshares_datadfr   s                 rS   get_shares_fullzTickerBase.get_shares_fullW  sT   $&&
""MY[mz{||||J!!%(((    ,,$$&&11"55(33E?&sB//C;C=",C0000EC<<LL89994C  hhsmm Nkokv  N  N  AE  AL  N  N#eec%//2C2C.D.DeesSVS`S`SbSbOcOcee
	
,,,<<I!((II%x':'KL 	 	 	LLDKSSSTTT44		Y'08MIDD 	 	 	DDD	 	LLDKSSSTTT4-h7{1~--4	;q>,7r~kZ[n]hNips?t?t?tuuuBB 	 	 	LLDKQQaQQRRR44444	 8''++]]__	s=   /F8 8=G98G9=H H%$H%$AJ' '
K1KKc                    |t           ur6t          j        dt          d           | j                            |           | j        | j        S | j                                        }d|v sd|v rd| _        | j        S |}| j	        j
        d S d| j	        j
        v r| j	        j
        d         }dt          |           }| j                            |          j        }d	| d
}||vrK|                                |                                v rd}||vrd| _        | j        S nd| _        | j        S |                    |          d                             d	          d                             d
          d         | _        | j        S )Nr'   r    r(   -^	shortNamezWhttps://markets.businessinsider.com/ajax/SearchController_Suggest?max_results=25&query=r  "|z"|r   r   )r   r:   r;   r<   r9   r=   r3   r0   r/   rF   ri   	urlencoderx   textlowersplit)rL   rM   r0   qrp   r~   
search_strs          rS   get_isinzTickerBase.get_isin  s   
""MY[mz{||||J!!%((( :!:""$$&==C6MMDJ:;#4$+*** -Avhqrshthtvvz###,,1"]]]
T!!wwyyDJJLL((!
T))!$DJ:% * !
z!ZZ
++A.44S99!<BB3GGJ
zrU   r^   newsc           	      t   | j         r| j         S t          j                    }|t          ur6t	          j        dt          d           | j                            |           dddd}|	                    |
                                          }|s:t          d| d	d
                    |                                                     t           d| d}d|| j        gdi}| j                            ||          }	|		d|	j        v rt%          d          	 |	                                }	n4# t(          j        $ r" |                    | j         d           i }	Y nw xY w|		                    di           	                    di           	                    dg           }
d |
D             | _         | j         S )z7Allowed options for tab: "news", "all", "press releasesr'   r    r(   newsAll
latestNewspressRelease)allr3  zpress releaseszInvalid tab name 'z'. Choose from: z, z/xhr/ncp?queryRef=z&serviceKey=ncp_finserviceConfig)snippetCountr  )bodyNzWill be right backz~*** YAHOO! FINANCE IS CURRENTLY DOWN! ***
Our engineers are working quickly to resolve the issue. Thank you for your patience.zC: Failed to retrieve the news and received faulty response instead.r~   tickerStreamstreamc                 >    g | ]}|                     d g           |S )ad)rz   ).0articles     rS   
<listcomp>z'TickerBase.get_news.<locals>.<listcomp>  s+    OOO'T29N9NOgOOOrU   )r4   r	   rw   r   r:   r;   r<   r9   r=   rz   r.  r-   joinkeysr   r0   postr-  RuntimeErrorry   r  r  rs   )rL   counttabrM   r}   tab_queryrefs	query_refrp   payloadr~   r3  s              rS   get_newszTickerBase.get_news  s   : 	:$&&
""MY[mz{||||J!!%(((  ,
 
 "%%ciikk22	 	jh#hhtyyQ^QcQcQeQeGfGfhhiiiMMyMMM %k] 
 zs11</49<<  I J J J	99;;DD$ 	 	 	LLDKlllmmmDDD	 xx##'';;??"MMOOTOOO
zs   D0 0.E! E!   r   c                 .    |                      ||          S rX   ) _get_earnings_dates_using_scrape)rL   limitoffsets      rS   get_earnings_dateszTickerBase.get_earnings_dates  s    44UFCCCrU   c                 t   |dk    r	|dk    rd}n-|dk    r	|dk    rd}n|dk    r	|dk    rd}nt          d          d                    | j        ||          }| j                            |          }t          |j        d          }|                    d          }|rbt          |          }t          |          }	t          j        |	d	g
          d         }
|
                    ddgd          }
|
                    ddid           |
                    d          }
|
d         j                            dd          |
d<   |
d         j                            dd          |
d<   |
d         j                            ddd          }|d         }|d         }t          j        |d          |
d<   t          j        d t'          |
d         |          D                       |
d<   |
                    d          }
n6d}t+          j                    }|                    | j         d|            dS |
S ) a  
        Uses YfData.cache_get() to scrape earnings data from YahooFinance.
        (https://finance.yahoo.com/calendar/earnings?symbol=INTC)
    
        Args:
            limit (int): Number of rows to extract (max=100)
            offset (int): if 0, search from future EPS estimates. 
                          if 1, search from the most recent EPS. 
                          if x, search from x'th recent EPS. 
    
        Returns:
            pd.DataFrame in the following format.
    
                       EPS Estimate Reported EPS Surprise(%)
            Date
            2025-10-30         2.97            -           -
            2025-07-22         1.73         1.54      -10.88
            2025-05-06         2.63          2.7        2.57
            2025-02-06         2.09         2.42       16.06
            2024-10-31         1.92         1.55      -19.36
            ...                 ...          ...         ...
            2014-07-31         0.61         0.65        7.38
            2014-05-01         0.55         0.68       22.92
            2014-02-13         0.55         0.58        6.36
            2013-10-31         0.51         0.54        6.86
            2013-08-01         0.46          0.5        7.86
        r      2   d   zPlease use limit <= 100zGhttps://finance.yahoo.com/calendar/earnings?symbol={}&offset={}&size={}zhtml.parsertabler'  )	na_valuesSymbolCompanyr   )axisSurprise (%)Surprise(%)TcolumnsinplaceEarnings Date)subsetEDTzAmerica/New_YorkESTrv   )nexpandz%B %d, %Y at %I %p)formatc                 >    g | ]\  }}|                     |          S  )r  )r@  dtrj   s      rS   rB  z?TickerBase._get_earnings_dates_using_scrape.<locals>.<listcomp>;  s(    ,l,l,lFBR^^B-?-?,l,l,lrU   z/No earnings dates found, symbol may be delisted: N)r-   rg  r0   r9   rx   r   r-  findstrr   r
  	read_htmldroprenamedropnareplacersplitr  r  zip	set_indexr	   rw   rs   )rL   rP  rQ  sizerp   responsesouprW  
table_htmlhtml_stringior$  dt_partsdtstzserr_msgr}   s                   rS   rO  z+TickerBase._get_earnings_dates_using_scrape  sc   @ 199"DDRZZERKKDDRZZESLLDD6777 X^^K
 
 :'',, X]M::		'"" "	UJ %Z00M mu===a@B (I.Q77B II~}=tILLL/22B #%_"5"9"A"A%I["\"\B"$_"5"9"A"A%I["\"\B/*.55cQt5LLH1+C1+C"$.=Q"R"R"RB"$),l,lcRTUdRegjNkNk,l,l,l"m"mBo..BB HG(**FLLDK447445554	rU   c                 "   t          j                    }|t          ur6t          j        dt
          d           | j                            |           t          |d          }| j	        r|| j	        v r| j	        |         S t           d}ddd}|d	d
| j        gddddg dd}| j                            |||          }|                                }	d |	d         d         d         d         d         d         D             }
|	d         d         d         d         d         d         }t          j        ||
          }|j        rDt#          | j                  }t%          |          }|                    | j         d|            dS |d                             ddd           |d<   |d                             d!d"d           |d<   |d                             d#d$d           |d<   t          j        |d%                   |d&<   |                     d'(          }|d&         j        j        $|d&         j                            |          |d&<   n#|d&         j                            |          |d&<   g d)}||                             d*                              d+t8          j                  ||<   |                    d%d,gd-d.           |                    d&d/           |                     d0d1id2           || j	        |<   |S )3a  
        Get earning dates (future and historic)

        In Summer 2025, Yahoo stopped updating the data at this endpoint.
        So reverting to scraping HTML.
        
        Args:
            limit (int): max amount of upcoming and recent earnings dates to return.
                Default value 12 should return next 4 quarters and last 8 quarters.
                Increase if more history is needed.
        Returns:
            pd.DataFrame
        r'   r    r(   rV  z/v1/finance/visualizationzen-USUS)langregioneqr0   )operatoroperandsstartdatetimeDESCr   )r  timeZoneShortNameepsestimate	epsactualepssurprisepct	eventtype)rv  query	sortFieldsortTypeentityIdTypeincludeFields)rq   r;  c                     g | ]
}|d          S )labelri  )r@  rows     rS   rB  zATickerBase._get_earnings_dates_using_screener.<locals>.<listcomp>n  s    hhhC3w<hhhrU   r  rt   r   	documentsr_  rows)r_  rk  Nz
Event Typez^1$CallT)regexz^2$Earningsz^11$MeetingzEvent Start Datera     r_   )r\  zEPS EstimatezReported EPSfloat64g        zTimezone short namer   )r[  r`  )r`  r\  r]  r^  )!r	   rw   r   r:   r;   r<   r9   r=   minr6   r   r0   rE  ry   r
  	DataFrameemptyr   rm  rs   rr  r  ra   rj  rj   r  r  astypenpnanro  ru  rp  )rL   rP  rM   r}   clamped_limitrp   rq   r;  rw  r!  r_  r  r$  
_exceptionr~  rj   columns_to_updates                    rS   "_get_earnings_dates_using_screenerz-TickerBase._get_earnings_dates_using_screenerE  sK    $&&
""MY[mz{||||J!!%(((E3 	7MT5I$I$I'66 888!T22!#'h5LNN(&~~~
 
 :??3vD?AAMMOO	 ih9Y+?+I!+L[+YZ[+\]f+ghhh#H-a0=a@H\$0008 	.t{;;J*ooGLLDK447445554 l+33E63NN<l+33E:T3RR<l+33FIT3RR< !nR0B-CDD?   ,,o!$,"$_"5"8"D"DR"H"HB"$_"5"8"C"CB"G"GB MLL "#4 5 < <Y G G O OPSUWU[ \ \ 	#%:;!TRRR
_d333
		>=94	HHH.0]+	rU   c                     |t           ur6t          j        dt          d           | j                            |           |                                                     |          S r   )r   r:   r;   r<   r9   r=   rY   get_history_metadatar   s     rS   r  zTickerBase.get_history_metadata  s]    
""MY[mz{||||J!!%(((,,..CCEJJJrU   c                     |t           ur6t          j        dt          d           | j                            |           | j        st          | j        | j                  | _        | j        S r   )	r   r:   r;   r<   r9   r=   rH   r   r0   r   s     rS   get_funds_datazTickerBase.get_funds_data  sh    
""MY[mz{||||J!!%((( 	B(T[AADrU   Tc                     || _         t          |          | _        | j                            | j                   | j                            | j                    d S )N)verbose)rJ   r   rK   	subscriber0   listen)rL   message_handlerr  s      rS   livezTickerBase.live  sQ     /G,,,$+&&&t,-----rU   )rM  r   )NT)?__name__
__module____qualname__r   rT   r	   log_indent_decoratorr
  r  rZ   rY   ra   rg   r   r   r   dictr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r%  r   rm  r2  listrL  rR  rO  r  r  r   r  r  ri  rU   rS   r   r   6   s       '+: I I I IV H", H H H  H
# # #
  B       D )3E     1;E 9 9 9 9 -7     ", $ $ $ $ $ $ %/ ' '4 ' ' ' ' '1%     /9% 	 	 	 	 ,6u 	 	 	 	 +5e 	 	 	 	 .8 	 	 	 	 0:5 	 	 	 	 (  D     #-     (25     /9 	 	T 	 	 	 	 +5e 
3 
3 
3 
3 *4U 
3 
3 
3 
3 *4U 
3 
3 
3 
3 #-e 
3 
3 
3 
3 '1% 
3 
3 
3 
3 *4U 
3 
3 
3 
3 ",U    0 %/eRZ    4 $.uUQY B B B B $.uUQY B B B B '1%T\    6 &0uS[ D D D D #-eEPX  ]bcecoqucu]v    6 ",U5x @ @ @ @ #-U L Lry L L L L '1 P P29 P P P P  *% I IBI I I I I !+5 J JRY J J J J  *5  U2<QUCU=V     $(d* 4 4 4  4l ( & &HSM & & & &P  V: + +$ + + + +ZD DHR\<R D D D D \ \(SUS_J` \ \ \  \| 79 L LPXY[YePf L L L  L\ *4 K K K K K K $.    (92E        . . . . . .rU   r   )4
__future__r   ry   r  r:   typingr   r   urllib.parser   r,  numpyr  pandasr
  	curl_cffir   r#   r	   r
   constr   r~   r   r  r   r   r  r   scrapers.analysisr   scrapers.fundamentalsr   scrapers.holdersr   scrapers.quoter   r   scrapers.historyr   scrapers.fundsr   r   r   r   r   ior   bs4r   rh   r   ri  rU   rS   <module>r     s  , & % % % % %      " " " " " " " " + + + + + +                       ' ' ' ' ' '       ? ? ? ? ? ? ? ?       ' ' ' ' ' ' / / / / / / % % % % % % + + + + + + + + * * * * * * % % % % % % C C C C C C C C C C C C              t. t. t. t. t. t. t. t. t. t.rU   