-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_inputs.py
44 lines (35 loc) · 1.31 KB
/
user_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Prompts for user input."""
import sys
from config import CONFIG
def handle_keyboard_interrupt(func):
"""Decorator to handle KeyboardInterrupt."""
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit()
return wrapper
def prompt_ticker_selection():
"""Prompt the user to choose a list of tickers."""
while True:
print("Choose a list of tickers:")
for i, ticker_list in enumerate(CONFIG['TICKERS_LISTS']):
print(f"{i+1}. {ticker_list['name']} ({ticker_list['description']})")
choice = input("Enter your choice: ")
if choice.isdigit() and 1 <= int(choice) <= len(CONFIG['TICKERS_LISTS']):
break
else:
print("Invalid choice. Please try again.")
return choice
def prompt_custom_ticker_list():
"""Prompt the user to enter a list of tickers."""
while True:
custom_tickers = input("Enter a list of tickers separated by commas: ").strip().split(',')
# Sanitize input
custom_tickers = [ticker.strip() for ticker in custom_tickers if ticker.strip()]
if not custom_tickers:
print("Invalid input. Please try again.")
else:
break
return custom_tickers