"""Configuration for Expense Tracker."""
from pathlib import Path
import json
# Paths
BASE_DIR = Path(__file__).parent
DATA_DIR = BASE_DIR / "data"
CATEGORIES_PATH = BASE_DIR / "resources" / "categories.json"
# Load categories from JSON
def load_categories():
"""Load categories and their structure from JSON file."""
try:
with open(CATEGORIES_PATH, 'r', encoding='utf-8') as f:
data = json.load(f)
categories = list(data.keys())
categories_structure = data
return categories, categories_structure
except FileNotFoundError:
# Default categories if file not found
default_categories = {
"food": ["groceries", "restaurant", "snacks"],
"transport": ["fuel", "public_transport", "taxi"],
"housing": ["rent", "mortgage", "maintenance"],
"utilities": ["electricity", "water", "internet"],
"health": ["medicine", "doctor", "insurance"],
"education": ["tuition", "books", "courses"],
"family_kids": ["childcare", "toys", "school_fees"],
"entertainment": ["movies", "games", "hobbies"],
"shopping": ["clothing", "electronics", "home"],
"subscriptions": ["streaming", "software", "memberships"],
"personal_care": ["salon", "gym", "skincare"],
"gifts_donations": ["birthday", "charity", "festivals"],
"finance_fees": ["bank_charges", "loan_interest", "tax_filing"],
"business": ["office_supplies", "travel", "equipment"],
"travel": ["flights", "hotels", "vacation"],
"home": ["furniture", "appliances", "repairs"],
"pet": ["food", "vet", "accessories"],
"taxes": ["income_tax", "property_tax", "gst"],
"investments": ["stocks", "mutual_funds", "fixed_deposits"],
"misc": ["other", "unexpected"]
}
categories = list(default_categories.keys())
categories_structure = default_categories
# Save default categories to file
CATEGORIES_PATH.parent.mkdir(parents=True, exist_ok=True)
with open(CATEGORIES_PATH, 'w', encoding='utf-8') as f:
json.dump(default_categories, f, indent=2, ensure_ascii=False)
return categories, categories_structure
CATEGORIES, CATEGORIES_STRUCTURE = load_categories()