File size: 617 Bytes
621ec47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551a064
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""

Utility functions shared across the application

"""
import os
import json


def load_settings(file_path):
    """Load settings from a JSON file"""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            return json.load(f)
    except FileNotFoundError:
        return {}
    except json.JSONDecodeError:
        return {}


def save_settings(file_path, data):
    """Save settings to a JSON file"""
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
    with open(file_path, 'w', encoding='utf-8') as f:
        json.dump(data, f, indent=2, ensure_ascii=False)