Add config
This commit is contained in:
parent
cc45c919f5
commit
9d35fb5002
|
@ -0,0 +1,49 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
default_config = {
|
||||
'color': (255, 0, 0),
|
||||
'brightness': 1.0,
|
||||
'color_format': 'RGB',
|
||||
'servers': [('192.168.0.201', 80)]
|
||||
}
|
||||
|
||||
config_file = 'config.json'
|
||||
|
||||
class ConfigHandler:
|
||||
def load_config(self):
|
||||
"""Load color, brightness, format, and server settings from config file."""
|
||||
if os.path.exists(config_file):
|
||||
with open(config_file, 'r') as f:
|
||||
return json.load(f)
|
||||
else:
|
||||
return default_config
|
||||
|
||||
def save_config(self, color, brightness, color_format, servers):
|
||||
"""Save color, brightness, format, and server settings to config file."""
|
||||
config = {
|
||||
'color': color,
|
||||
'brightness': brightness,
|
||||
'color_format': color_format,
|
||||
'servers': servers
|
||||
}
|
||||
with open(config_file, 'w') as f:
|
||||
json.dump(config, f)
|
||||
print("Configuration saved.")
|
||||
|
||||
def add_server(self, ip, port):
|
||||
"""Add a new server IP and port."""
|
||||
config = self.load_config()
|
||||
config['servers'].append((ip, port))
|
||||
self.save_config(config['color'], config['brightness'], config['color_format'], config['servers'])
|
||||
print(f"Server {ip}:{port} added.")
|
||||
|
||||
def remove_server(self, ip, port):
|
||||
"""Remove an existing server IP and port."""
|
||||
config = self.load_config()
|
||||
if (ip, port) in config['servers']:
|
||||
config['servers'].remove((ip, port))
|
||||
self.save_config(config['color'], config['brightness'], config['color_format'], config['servers'])
|
||||
print(f"Server {ip}:{port} removed.")
|
||||
else:
|
||||
print(f"Server {ip}:{port} not found.")
|
Loading…
Reference in New Issue