From 8ea0895f7385fae56c970e3bd6e59c1cb399ee91 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Wed, 12 Feb 2025 19:47:56 -0800 Subject: [PATCH] refactor: Resolve circular import by moving get_user_input to scanner_utils.py --- src/utils/data_utils.py | 31 +------------------------------ src/utils/scanner_utils.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/utils/data_utils.py b/src/utils/data_utils.py index 7db5b0f..2f2be0c 100644 --- a/src/utils/data_utils.py +++ b/src/utils/data_utils.py @@ -5,38 +5,9 @@ from datetime import datetime, timedelta from db.db_connection import create_client from screener.user_input import get_interval_choice, get_date_range from trading.position_calculator import PositionCalculator -from utils.scanner_utils import initialize_scanner - +from utils.scanner_utils import initialize_scanner, get_user_input from typing import Optional -def get_user_input(prompt: str, input_type: type = str, allow_empty: bool = False) -> Optional[any]: - """ - Get user input with escape option - - Args: - prompt (str): Input prompt to display - input_type (type): Expected input type (str, float, int) - allow_empty (bool): Whether to allow empty input - - Returns: - Optional[any]: Converted input value or None if user wants to exit - """ - while True: - value = input(f"{prompt} (q to quit): ").strip() - - if value.lower() in ['q', 'quit', 'exit']: - return None - - if not value and allow_empty: - return None - - try: - if input_type == bool: - return value.lower() in ['y', 'yes', 'true', '1'] - return input_type(value) - except ValueError: - print(f"Please enter a valid {input_type.__name__}") - def get_float_input(prompt: str) -> Optional[float]: return get_user_input(prompt, float) diff --git a/src/utils/scanner_utils.py b/src/utils/scanner_utils.py index cbf64c7..123a4f2 100644 --- a/src/utils/scanner_utils.py +++ b/src/utils/scanner_utils.py @@ -1,7 +1,36 @@ from datetime import datetime, timedelta -from utils.data_utils import get_user_input, get_stock_data, get_qualified_stocks +from utils.data_utils import get_stock_data, get_qualified_stocks from screener.user_input import get_interval_choice, get_date_range from trading.position_calculator import PositionCalculator +from typing import Optional + +def get_user_input(prompt: str, input_type: type = str, allow_empty: bool = False) -> Optional[any]: + """ + Get user input with escape option + + Args: + prompt (str): Input prompt to display + input_type (type): Expected input type (str, float, int) + allow_empty (bool): Whether to allow empty input + + Returns: + Optional[any]: Converted input value or None if user wants to exit + """ + while True: + value = input(f"{prompt} (q to quit): ").strip() + + if value.lower() in ['q', 'quit', 'exit']: + return None + + if not value and allow_empty: + return None + + try: + if input_type == bool: + return value.lower() in ['y', 'yes', 'true', '1'] + return input_type(value) + except ValueError: + print(f"Please enter a valid {input_type.__name__}") def initialize_scanner(min_price: float, max_price: float, min_volume: int, portfolio_size: float = None, interval: str = "1d",