GGGISfolio / src /data_manager.py
miniwa00's picture
디버그 둜그λ₯Ό κ°„μ†Œν™”ν•˜κΈ° μœ„ν•΄ save_nodes, save_ideas, load_nodes, load_ideas ν•¨μˆ˜μ—μ„œ λΆˆν•„μš”ν•œ 좜λ ₯문을 μ œκ±°ν•¨. 아이디어 및 λ…Έλ“œ 생성 λ‘œμ§μ—μ„œλ„ 디버그 둜그λ₯Ό μ •λ¦¬ν•˜μ—¬ μ½”λ“œ 가독성을 ν–₯μƒμ‹œν‚΄.
5610747
Raw
History Blame Contribute Delete
1.88 kB
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