# -*- coding: utf-8 -*-
import json
tree=json.load(open('_gnb_tree.json',encoding='utf-8'))
gnb=[]
for t in tree:
    gnb.append({'depth':1,'label':t['t'].strip(),'href':t['h']})
    for m in t['mids']:
        gnb.append({'depth':2,'label':m['t'].strip(),'href':m['h']})
        for l in m['leaves']:
            gnb.append({'depth':3,'label':l['t'].strip(),'href':l['h']})
out={'num':3,'name':'한국조세재정연구원','base':'https://www.kipf.re.kr/kor/','gnb':gnb}
import os
os.makedirs(r'D:\01.프로젝트\DB수집\작업파일\공공기관2\_gnb',exist_ok=True)
json.dump(out,open(r'D:\01.프로젝트\DB수집\작업파일\공공기관2\_gnb\3.json','w',encoding='utf-8'),ensure_ascii=False,indent=1)
print('gnb rows:',len(gnb))
from collections import Counter
print('depth분포:',dict(Counter(g['depth'] for g in gnb)))
