import json, os

files = [f for f in os.listdir('input') if f.endswith('_制作表.json')]
files.sort()

for fname in files:
    with open(f'input/{fname}', 'r') as f:
        data = json.load(f)
    
    img_id = fname.split('__')[1].split('_')[0]
    print(f'\n=== {img_id} ({fname}) ===')
    
    def extract_key_info(items, depth=0):
        if isinstance(items, list):
            for item in items:
                extract_key_info(item, depth)
        elif isinstance(items, dict):
            pid = items.get('段落ID', '')
            name = items.get('名称', '')
            desc = items.get('描述', '')
            
            # 实质信息
            shizhi = items.get('实质', {})
            if shizhi:
                print(f'  [{pid}] {name}: {desc[:80]}')
                for k, v in shizhi.items():
                    if isinstance(v, dict):
                        vdesc = v.get('描述', '')
                        print(f'    实质.{k}: {vdesc[:100]}')
            elif pid:
                print(f'  [{pid}] {name}: {desc[:80]}')
            
            children = items.get('子段落', [])
            if children:
                extract_key_info(children, depth+1)
    
    extract_key_info(data)
