# coding: utf-8
import openpyxl, io, re
wb=openpyxl.load_workbook('한국인터넷진흥원.xlsx'); ws=wb.active
out=io.open('_tree_out.txt','w',encoding='utf-8')
def seq_of(u):
    m=re.search(r'kisa\.or\.kr/(\d+)',u or ''); return m.group(1) if m else (u or '')
for r in range(3,ws.max_row+1):
    b=ws.cell(r,2).value
    d=[ws.cell(r,c).value for c in range(4,11)]
    k=ws.cell(r,11).value
    L=ws.cell(r,12).value; M=ws.cell(r,13).value
    # compact depth display
    parts=[('%s'%v) for v in d if v not in (None,'')]
    out.write('r%-3d B%-3s | %-55s | seq=%-9s L=%s M=%s\n'%(
        r,b,' > '.join(parts),seq_of(k),L,M))
out.close(); print('done')
