always add OTHER entry
This commit is contained in:
parent
215ed9060e
commit
d8c9c26545
@ -34,27 +34,22 @@ def load_config(config_path):
|
||||
Returns:
|
||||
list: List of configured lines with name, message count, and accounts
|
||||
"""
|
||||
# Default configuration
|
||||
# Default configuration (used if file doesn't exist)
|
||||
default_lines = [
|
||||
[" ONE", 0, ['one@example.com']],
|
||||
[" TWO", 0, ['two@example.com']],
|
||||
[" THREE", 0, ['three@example.com']],
|
||||
[" FOUR", 0, ['four@example.com']],
|
||||
[" FIVE", 0, ['five@exmaple.com']],
|
||||
[" OTHER", 0, ['']],
|
||||
]
|
||||
|
||||
# Create config parser
|
||||
config = configparser.ConfigParser()
|
||||
|
||||
# Check if config file exists
|
||||
if not os.path.exists(config_path):
|
||||
logger.warning(f"Config file not found at {config_path}. Using default configuration.")
|
||||
# Create directory if it doesn't exist
|
||||
os.makedirs(os.path.dirname(config_path), exist_ok=True)
|
||||
|
||||
# Create default config file
|
||||
config['DEFAULT'] = {'max_lines': '6'}
|
||||
config['DEFAULT'] = {'max_lines': '5'} #limit to 5 from config
|
||||
for i, line in enumerate(default_lines):
|
||||
section = f'line{i+1}'
|
||||
config[section] = {
|
||||
@ -62,11 +57,35 @@ def load_config(config_path):
|
||||
'accounts': ','.join(line[2])
|
||||
}
|
||||
|
||||
# Write default config
|
||||
with open(config_path, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
return default_lines
|
||||
result = [ [line[0], line[1], line[2]] for line in default_lines]
|
||||
result.append([" OTHER", 0, ['']])
|
||||
return result
|
||||
|
||||
try:
|
||||
config.read(config_path)
|
||||
max_lines = int(config['DEFAULT'].get('max_lines', '5')) #get max lines from config, default to 5.
|
||||
|
||||
configured_lines = []
|
||||
for i in range(1, max_lines + 1):
|
||||
section = f'line{i}'
|
||||
if section in config:
|
||||
name = ' ' + config[section].get('name', '').strip()
|
||||
accounts_str = config[section].get('accounts', '')
|
||||
accounts = [acc.strip() for acc in accounts_str.split(',') if acc.strip()]
|
||||
configured_lines.append([name, 0, accounts])
|
||||
else:
|
||||
break #stop if no more config sections.
|
||||
|
||||
configured_lines.append([" OTHER", 0, ['']]) #always add OTHER
|
||||
return configured_lines
|
||||
except (configparser.Error, ValueError) as e:
|
||||
logger.error(f"Error reading config file: {e}. Using default configuration and adding OTHER.")
|
||||
result = [ [line[0], line[1], line[2]] for line in default_lines]
|
||||
result.append([" OTHER", 0, ['']])
|
||||
return result
|
||||
|
||||
# Read config file
|
||||
config.read(config_path)
|
||||
|
Loading…
Reference in New Issue
Block a user