mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
* Opening Bell Introducing the Stock Ticker Feature * Update stock_manager.py Assume folder exists * Update stock_manager.py removing logos to focus on function for now * Update stock_manager.py parse yahoo scripts * Update stock_manager.py stock query update * Update stock_manager.py slow down stock display * Update display_controller.py adjust screen flow * Update stock_manager.py shipping features * Update stock_manager.py stock refresh in the background * Customize Display timings customize display timings * Update stock_manager.py stock font size change * Sizing and Spacing CHanged font sizing on chart and clock spacing * Update clock.py Date format changes * Update stock_manager.py actually read stocks from config file * Update stock_manager.py add config manager * readme update readme update and formatting for better flow * Update .gitignore rename reference folder * Update config.json changed default stocks to test update implementation * Stock News Stock news Ticker * Update config.json increase scroll speed * Scroll Performance Tuning news scrolling performance * updating scroll direction orienting scroll direction * News tuning removed test files and increased scroll speed * Create test_news_manager.py need a test script to call upon * Update test_news_manager.py test script tuning * troubleshooting test script * Update test_news_manager.py * Update config.json scroll speed increases * Update config.json scroll tuning * Update config.json speeding up * Update config.json still making text faster * Update config.json Trying to tune scrolling * Update config.json testing crazy parameters * Update test_news_manager.py remove sleep delay * scroll tuning scroll tuning * scroll logging and debugging FPS counter and debug messages * Update config.json matrix speed tuning * Update news_manager.py News separator * Update news_manager.py separator character change * Stock News manager Rename rename stock news ticker to enable other news in the future * Update display_controller.py load config update * Update stock_manager.py remove redundant import * Stock news settings Stock news has more granular control * Stock news joins the lineup Stock News added to the display controller and drawing display instead of image
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
import json
|
|
import os
|
|
from typing import Dict, Any
|
|
|
|
class ConfigManager:
|
|
def __init__(self, config_path: str = None, secrets_path: str = None):
|
|
# Use current working directory as base
|
|
self.config_path = config_path or "config/config.json"
|
|
self.secrets_path = secrets_path or "config/config_secrets.json"
|
|
self.config: Dict[str, Any] = {}
|
|
|
|
def load_config(self) -> Dict[str, Any]:
|
|
"""Load configuration from JSON files."""
|
|
try:
|
|
# Load main config
|
|
print(f"Attempting to load config from: {os.path.abspath(self.config_path)}")
|
|
with open(self.config_path, 'r') as f:
|
|
self.config = json.load(f)
|
|
|
|
# Load and merge secrets if they exist
|
|
if os.path.exists(self.secrets_path):
|
|
with open(self.secrets_path, 'r') as f:
|
|
secrets = json.load(f)
|
|
# Deep merge secrets into config
|
|
self._deep_merge(self.config, secrets)
|
|
|
|
return self.config
|
|
|
|
except FileNotFoundError as e:
|
|
if str(e).find('config_secrets.json') == -1: # Only raise if main config is missing
|
|
print(f"Configuration file not found at {os.path.abspath(self.config_path)}")
|
|
raise
|
|
return self.config
|
|
except json.JSONDecodeError:
|
|
print("Error parsing configuration file")
|
|
raise
|
|
except Exception as e:
|
|
print(f"Error loading configuration: {str(e)}")
|
|
raise
|
|
|
|
def _deep_merge(self, target: Dict, source: Dict) -> None:
|
|
"""Deep merge source dict into target dict."""
|
|
for key, value in source.items():
|
|
if key in target and isinstance(target[key], dict) and isinstance(value, dict):
|
|
self._deep_merge(target[key], value)
|
|
else:
|
|
target[key] = value
|
|
|
|
def get_timezone(self) -> str:
|
|
"""Get the configured timezone."""
|
|
return self.config.get('timezone', 'UTC')
|
|
|
|
def get_display_config(self) -> Dict[str, Any]:
|
|
"""Get display configuration."""
|
|
return self.config.get('display', {})
|
|
|
|
def get_clock_config(self) -> Dict[str, Any]:
|
|
"""Get clock configuration."""
|
|
return self.config.get('clock', {}) |