chore(dataflows): use the module logger and drop dead helpers

- four modules wrote to stdout with print() while ten others use a module
  logger; a warning printed into the rendered CLI output is effectively
  invisible, which is how the trim failure above went unnoticed
- convert the remaining calls to logger.warning with lazy formatting
- remove save_output, SavePathType, decorate_all_methods and get_next_weekday
  from utils, none of which had a caller, along with the pandas and typing
  imports that only they needed
This commit is contained in:
Yijia-Xiao
2026-09-07 21:28:52 +00:00
parent 16f7fd613c
commit ffd5d9a180
3 changed files with 11 additions and 40 deletions

View File

@@ -1,5 +1,9 @@
import logging
from .alpha_vantage_common import AlphaVantageNotConfiguredError, _make_api_request
logger = logging.getLogger(__name__)
def get_indicator(
symbol: str,
@@ -211,5 +215,5 @@ def get_indicator(
# successful-looking error string.
raise
except Exception as e:
print(f"Error getting Alpha Vantage indicator data for {indicator}: {e}")
logger.warning("Alpha Vantage indicator %s failed: %s", indicator, e)
return f"Error retrieving {indicator} data: {str(e)}"

View File

@@ -1,10 +1,5 @@
import re
from datetime import date, datetime, timedelta
from typing import Annotated
import pandas as pd
SavePathType = Annotated[str, "File path to save data. If None, data is not saved."]
from datetime import date
# Tickers can contain letters, digits, dot, dash, underscore, caret
# (index symbols like ^GSPC), equals (futures like GC=F), and plus
@@ -42,34 +37,5 @@ def safe_ticker_component(value: str, *, max_len: int = 32) -> str:
return value
def save_output(data: pd.DataFrame, tag: str, save_path: SavePathType = None) -> None:
if save_path:
data.to_csv(save_path, encoding="utf-8")
print(f"{tag} saved to {save_path}")
def get_current_date():
return date.today().strftime("%Y-%m-%d")
def decorate_all_methods(decorator):
def class_decorator(cls):
for attr_name, attr_value in cls.__dict__.items():
if callable(attr_value):
setattr(cls, attr_name, decorator(attr_value))
return cls
return class_decorator
def get_next_weekday(date):
if not isinstance(date, datetime):
date = datetime.strptime(date, "%Y-%m-%d")
if date.weekday() >= 5:
days_to_add = 7 - date.weekday()
next_weekday = date + timedelta(days=days_to_add)
return next_weekday
else:
return date

View File

@@ -1,3 +1,4 @@
import logging
from datetime import datetime
from typing import Annotated
@@ -15,6 +16,8 @@ from .stockstats_utils import (
)
from .symbol_utils import NoMarketDataError, normalize_symbol
logger = logging.getLogger(__name__)
def get_YFin_data_online(
symbol: Annotated[str, "ticker symbol of the company"],
@@ -189,7 +192,7 @@ def get_stock_stats_indicators_window(
except NoMarketDataError:
raise # Unknown/delisted symbol — let the router emit the sentinel
except Exception as e:
print(f"Error getting bulk stockstats data: {e}")
logger.warning("Bulk stockstats fetch failed, falling back per-day: %s", e)
# Fallback to original implementation if bulk method fails
ind_string = ""
curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d")
@@ -264,9 +267,7 @@ def get_stockstats_indicator(
except NoMarketDataError:
raise # Unknown/delisted symbol — let the router emit the sentinel
except Exception as e:
print(
f"Error getting stockstats indicator data for indicator {indicator} on {curr_date}: {e}"
)
logger.warning("Stockstats indicator %s failed on %s: %s", indicator, curr_date, e)
return ""
return str(indicator_value)