Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| # μ μ λ³μ | |
| nodes_data = [] | |
| ideas_data = [] | |
| def save_nodes(): | |
| """λ Έλ λ°μ΄ν°λ₯Ό JSON νμΌλ‘ μ μ₯""" | |
| try: | |
| # data λλ ν 리 μμ± | |
| os.makedirs("data", exist_ok=True) | |
| with open("data/nodes_data.json", "w", encoding="utf-8") as f: | |
| json.dump(nodes_data, f, ensure_ascii=False, indent=2) | |
| except Exception as e: | |
| print(f"[ERROR] save_nodes μ€ν¨: {e}") | |
| raise e | |
| def save_ideas(): | |
| """μμ΄λμ΄ λ°μ΄ν°λ₯Ό JSON νμΌλ‘ μ μ₯""" | |
| try: | |
| # data λλ ν 리 μμ± | |
| os.makedirs("data", exist_ok=True) | |
| with open("data/ideas_data.json", "w", encoding="utf-8") as f: | |
| json.dump(ideas_data, f, ensure_ascii=False, indent=2) | |
| except Exception as e: | |
| print(f"[ERROR] save_ideas μ€ν¨: {e}") | |
| raise e | |
| def load_nodes(): | |
| """μ μ₯λ λ Έλ λ°μ΄ν° λΆλ¬μ€κΈ°""" | |
| global nodes_data | |
| if os.path.exists("data/nodes_data.json"): | |
| try: | |
| with open("data/nodes_data.json", "r", encoding="utf-8") as f: | |
| nodes_data = json.load(f) | |
| except (json.JSONDecodeError, ValueError): | |
| nodes_data = [] | |
| else: | |
| nodes_data = [] | |
| def load_ideas(): | |
| """μ μ₯λ μμ΄λμ΄ λ°μ΄ν° λΆλ¬μ€κΈ°""" | |
| global ideas_data | |
| if os.path.exists("data/ideas_data.json"): | |
| try: | |
| with open("data/ideas_data.json", "r", encoding="utf-8") as f: | |
| ideas_data = json.load(f) | |
| except (json.JSONDecodeError, ValueError): | |
| ideas_data = [] | |
| else: | |
| ideas_data = [] | |
| def initialize_data(): | |
| """μ± μμ μ λ°μ΄ν° μ΄κΈ°ν""" | |
| load_nodes() | |
| load_ideas() | |
| def get_ideas_data(): | |
| """ideas_data λ°ν""" | |
| return ideas_data | |
| def get_nodes_data(): | |
| """nodes_data λ°ν""" | |
| return nodes_data | |