BalanceBoard - Clean release

- Docker deployment ready
- Content aggregation and filtering
- User authentication
- Polling service for updates

🤖 Generated with Claude Code
This commit is contained in:
2025-10-11 21:24:21 +00:00
commit cb894b2159
53 changed files with 13514 additions and 0 deletions

57
utils.py Normal file
View File

@@ -0,0 +1,57 @@
"""
Utilities Library
Generic utility functions shared across modules.
"""
import uuid
import json
from pathlib import Path
from typing import Dict, Any
def generate_uuid() -> str:
"""Generate a new UUID string"""
return str(uuid.uuid4())
def load_json_file(file_path: str) -> Any:
"""Load JSON from file"""
with open(file_path, 'r') as f:
return json.load(f)
def save_json_file(data: Any, file_path: str, indent: int = 2):
"""Save data to JSON file"""
path = Path(file_path)
path.parent.mkdir(parents=True, exist_ok=True)
with open(path, 'w') as f:
json.dump(data, f, indent=indent)
def ensure_directory(dir_path: str) -> Path:
"""Create directory if it doesn't exist, return Path object"""
path = Path(dir_path)
path.mkdir(parents=True, exist_ok=True)
return path
def load_json_files_from_dir(dir_path: str, pattern: str = "*.json") -> Dict[str, Any]:
"""Load all JSON files from directory into dict keyed by filename (without extension)"""
directory = Path(dir_path)
data = {}
if directory.exists():
for file_path in directory.glob(pattern):
key = file_path.stem # filename without extension
data[key] = load_json_file(str(file_path))
return data
def count_files(dir_path: str, pattern: str = "*.json") -> int:
"""Count files matching pattern in directory"""
directory = Path(dir_path)
if not directory.exists():
return 0
return len(list(directory.glob(pattern)))