Rewritten financial data fetching so it finally works again.
This commit is contained in:
28
fetch_market_cap.py
Normal file
28
fetch_market_cap.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# fetch_market_cap.py
|
||||
# This script does ONLY ONE THING: gets the market cap.
|
||||
import sys
|
||||
import json
|
||||
import yfinance as yf
|
||||
import logging
|
||||
|
||||
# Suppress verbose yfinance logging in this isolated process
|
||||
logging.getLogger("yfinance").setLevel(logging.CRITICAL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
# Exit with an error code if no ticker is provided
|
||||
sys.exit(1)
|
||||
|
||||
ticker_symbol = sys.argv[1]
|
||||
|
||||
try:
|
||||
# Directly get the market cap
|
||||
market_cap = yf.Ticker(ticker_symbol).info.get('marketCap')
|
||||
|
||||
# On success, print JSON to stdout and exit cleanly
|
||||
print(json.dumps({"market_cap": market_cap}))
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
# If any error occurs, print an empty JSON and exit with an error code
|
||||
print(json.dumps({"market_cap": None}))
|
||||
sys.exit(1)
|
Reference in New Issue
Block a user