64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import json
|
|
import os
|
|
|
|
DATA_DIR = os.path.join(os.path.dirname(__file__), '..', 'data')
|
|
BUILDING_BLOCKS_DIR = os.path.join(os.path.dirname(__file__), '..', 'building_blocks')
|
|
|
|
def load_json_file(file_path):
|
|
"""Loads a JSON file from the given path."""
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
return data
|
|
except FileNotFoundError:
|
|
print(f"Error: File not found at {file_path}")
|
|
return None
|
|
except json.JSONDecodeError:
|
|
print(f"Error: Could not decode JSON from {file_path}")
|
|
return None
|
|
except Exception as e:
|
|
print(f"An unexpected error occurred while loading {file_path}: {e}")
|
|
return None
|
|
|
|
def get_value_ranges():
|
|
"""Loads value_ranges.json data."""
|
|
file_path = os.path.join(DATA_DIR, 'value_ranges.json')
|
|
return load_json_file(file_path)
|
|
|
|
def get_names_data():
|
|
"""Loads names.json data."""
|
|
file_path = os.path.join(DATA_DIR, 'names.json')
|
|
return load_json_file(file_path)
|
|
|
|
def get_text_snippets():
|
|
"""Loads text_snippets.json data."""
|
|
file_path = os.path.join(DATA_DIR, 'text_snippets.json')
|
|
return load_json_file(file_path)
|
|
|
|
def get_financial_concepts():
|
|
"""Loads financial_concepts.json data."""
|
|
file_path = os.path.join(BUILDING_BLOCKS_DIR, 'financial_concepts.json')
|
|
return load_json_file(file_path)
|
|
|
|
if __name__ == '__main__':
|
|
# Test functions
|
|
value_ranges = get_value_ranges()
|
|
if value_ranges:
|
|
print("Successfully loaded value_ranges.json")
|
|
# print(json.dumps(value_ranges, indent=2))
|
|
|
|
names_data = get_names_data()
|
|
if names_data:
|
|
print("Successfully loaded names.json")
|
|
# print(json.dumps(names_data, indent=2))
|
|
|
|
text_snippets = get_text_snippets()
|
|
if text_snippets:
|
|
print("Successfully loaded text_snippets.json")
|
|
# print(json.dumps(text_snippets, indent=2))
|
|
|
|
financial_concepts = get_financial_concepts()
|
|
if financial_concepts:
|
|
print("Successfully loaded financial_concepts.json")
|
|
# print(json.dumps(financial_concepts, indent=2))
|