refactor: Resolve circular import by moving get_user_input to scanner_utils.py
This commit is contained in:
parent
7d7262fd8c
commit
8ea0895f73
@ -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)
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user