Spaces:
Sleeping
Sleeping
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
|