Files
reddit_stock_analyzer/yfinance_test.py

50 lines
1.9 KiB
Python

# yfinance_test.py
# A standalone script to diagnose the persistent yfinance issue.
import yfinance as yf
import logging
# Set up a simple logger to see detailed error tracebacks
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
# A list of tickers to test. One very common one, and two from your logs.
TICKERS_TO_TEST = ["MSFT", "AEBI", "AEHR"]
print("--- Starting YFINANCE Diagnostic Test ---")
for ticker_symbol in TICKERS_TO_TEST:
print(f"\n--- Testing Ticker: {ticker_symbol} ---")
# --- Test 1: The Ticker().info method ---
try:
logging.info(f"Attempting to create Ticker object and get .info for {ticker_symbol}...")
ticker_obj = yf.Ticker(ticker_symbol)
market_cap = ticker_obj.info.get('marketCap')
if market_cap is not None:
logging.info(f"SUCCESS: Got market cap for {ticker_symbol}: {market_cap}")
else:
logging.warning(f"PARTIAL SUCCESS: .info call for {ticker_symbol} worked, but no market cap was found.")
except Exception:
logging.error(f"FAILURE: An error occurred during the Ticker().info call for {ticker_symbol}.", exc_info=True)
# --- Test 2: The yf.download() method ---
try:
logging.info(f"Attempting yf.download() for {ticker_symbol}...")
data = yf.download(
ticker_symbol,
period="2d",
progress=False,
auto_adjust=False
)
if not data.empty:
logging.info(f"SUCCESS: yf.download() for {ticker_symbol} returned {len(data)} rows of data.")
else:
logging.warning(f"PARTIAL SUCCESS: yf.download() for {ticker_symbol} worked, but returned no data (likely delisted).")
except Exception:
logging.error(f"FAILURE: An error occurred during the yf.download() call for {ticker_symbol}.", exc_info=True)
print("\n--- YFINANCE Diagnostic Test Complete ---")