File size: 1,881 Bytes
6f6b7d0
 
 
 
 
 
 
 
 
 
30da56a
 
 
 
 
 
 
 
 
 
6f6b7d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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