Format all code.
This commit is contained in:
@@ -13,26 +13,25 @@ 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:
|
||||
# Instead of the global yf.download(), we use the Ticker object's .history() method.
|
||||
# This uses a different internal code path that we have proven is stable.
|
||||
ticker = yf.Ticker(ticker_symbol)
|
||||
data = ticker.history(period="2d", auto_adjust=False)
|
||||
# --- END OF FIX ---
|
||||
|
||||
|
||||
closing_price = None
|
||||
if not data.empty:
|
||||
last_close_raw = data['Close'].iloc[-1]
|
||||
last_close_raw = data["Close"].iloc[-1]
|
||||
if pd.notna(last_close_raw):
|
||||
closing_price = float(last_close_raw)
|
||||
|
||||
|
||||
# On success, print JSON to stdout and exit cleanly
|
||||
print(json.dumps({"closing_price": closing_price}))
|
||||
sys.exit(0)
|
||||
except Exception:
|
||||
# If any error occurs, print an empty JSON and exit with an error code
|
||||
print(json.dumps({"closing_price": None}))
|
||||
sys.exit(1)
|
||||
sys.exit(1)
|
||||
|
Reference in New Issue
Block a user