print("="*50);print("!!! WARNING: 'vaderSentiment' library not found. News Sentiment features will be disabled in app.py. !!!");print("!!! Run: pip install vaderSentiment !!!");print("="*50)
ifnotdataor'historical'notindataornotisinstance(data['historical'],list):print(f"--- Warning: No valid 'historical' data found for FMP symbol {symbol}. ---");all_symbols_data[col_name]=[];time.sleep(0.5);continue
historical_data=data['historical'];symbol_data=[]
forentryinhistorical_data:
try:date_val=pd.to_datetime(entry['date']);close_price=float(entry['close']);symbol_data.append({'ds_date':date_val,col_name:close_price})# Renamed date to date_val
except (KeyError,ValueError,TypeError)asproc_e:print(f"--- Warning: Skipping FMP entry for {symbol} due to processing error: {entry} | Error: {proc_e} ---")
all_symbols_data[col_name]=symbol_data;print(f"--- Processed {len(symbol_data)} data points for FMP symbol {symbol}. ---");time.sleep(0.5)
exceptrequests.exceptions.RequestExceptionase:print(f"!!! Error fetching FMP data for {symbol}: {e} !!!");all_symbols_data[col_name]=[];time.sleep(1)
exceptjson.JSONDecodeErrorase:print(f"!!! Error decoding FMP JSON for {symbol}: {e} !!!");all_symbols_data[col_name]=[];time.sleep(1)
exceptExceptionase:print(f"!!! An unexpected error occurred fetching FMP data for {symbol}: {e} !!!");all_symbols_data[col_name]=[];time.sleep(1)
print(f"--- Fetched Current F&G: Value={current_data.get('value')}, Class={current_data.get('classification')} ---")
returncurrent_data
else:
print(f"--- Warning: Unexpected format received for current F&G data: {current_data} ---")
returnNone
exceptExceptionase:
print(f"!!! Error fetching current Fear & Greed Index: {e} !!!")
traceback.print_exc()
returnNone
# NewsAPI free tier limit: ~1 month. Adjust start date if necessary.
max_hist_days=30
if (end_date-start_date).days>max_hist_days:
start_date=end_date-timedelta(days=max_hist_days)
print(f"--- Warning: Historical news date range exceeds NewsAPI free tier limit (~1 month). Adjusted start date to {start_date.strftime('%Y-%m-%d')}. ---")