RewardApp / trash /logic /utils.py
Mhdeusi's picture
Rename logic/utils.py to trash/logic/utils.py
2707a7d verified
import json
import os
def load_json(file_path):
"""بارگذاری فایل JSON"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
print(f"File not found: {file_path}")
return None
except json.JSONDecodeError:
print(f"Invalid JSON in: {file_path}")
return None
def save_json(data, file_path):
"""ذخیره داده در فایل JSON"""
try:
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
return True
except Exception as e:
print(f"Error saving file: {e}")
return False