-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_profiles.py
29 lines (26 loc) · 1 KB
/
load_profiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import json
import logging
from typing import List
from profile_scheme import Profile
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def load_profiles(file_name: str) -> List[Profile]:
try:
logger.info(f"Loading profiles from file: {file_name}")
with open(file_name, 'r') as file:
profiles_data = json.load(file)
logger.debug(f"Loaded {len(profiles_data)} profiles")
return [Profile(**profile) for profile in profiles_data]
except FileNotFoundError:
logger.error(f"File not found: {file_name}")
print(f"Error: File '{file_name}' not found.")
sys.exit(1)
except json.JSONDecodeError as e:
logger.error(f"Error decoding JSON in '{file_name}': {e}")
print(f"Error decoding JSON in '{file_name}': {e}")
sys.exit(1)
except Exception as e:
logger.error(f"Error loading profiles from file: {e}")
print(f"Error loading profiles from file: {e}")
sys.exit(1)