Files
Gloria/diagnose_2025.py

109 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""
诊断脚本:检查 2025.06 页面的子页面结构
"""
import asyncio
import httpx
from config import settings
async def check_page_children(page_id: str):
"""检查页面的直接子页面"""
base_url = settings.CONFLUENCE_BASE_URL.rstrip('/')
token = settings.CONFLUENCE_TOKEN
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Accept": "application/json"
}
async with httpx.AsyncClient(headers=headers, timeout=30.0) as client:
# 1. 获取页面基本信息
url = f"{base_url}/rest/api/content/{page_id}"
print(f"\n=== 页面 {page_id} 基本信息 ===")
try:
response = await client.get(url)
response.raise_for_status()
data = response.json()
print(f"标题: {data.get('title', 'N/A')}")
print(f"类型: {data.get('type', 'N/A')}")
print(f"状态: {data.get('status', 'N/A')}")
except Exception as e:
print(f"获取页面信息失败: {e}")
return
# 2. 获取直接子页面
url = f"{base_url}/rest/api/content/{page_id}/child/page"
params = {
"limit": 100,
"expand": "_links"
}
print(f"\n=== 页面 {page_id} 的直接子页面 ===")
try:
response = await client.get(url, params=params)
response.raise_for_status()
data = response.json()
results = data.get('results', [])
size = data.get('size', 0)
print(f"子页面总数: {size}")
print(f"返回的子页面数: {len(results)}")
if results:
print("\n子页面列表:")
for i, child in enumerate(results, 1):
child_id = child.get('id', 'N/A')
title = child.get('title', 'N/A')
child_type = child.get('type', 'N/A')
print(f" {i}. ID: {child_id}, 标题: {title}, 类型: {child_type}")
# 递归检查每个子页面的子页面
await check_grandchildren(client, base_url, child_id, depth=1)
else:
print(" 该页面没有子页面")
except Exception as e:
print(f"获取子页面失败: {e}")
async def check_grandchildren(client, base_url, page_id, depth=1):
"""递归检查孙页面"""
url = f"{base_url}/rest/api/content/{page_id}/child/page"
params = {"limit": 100}
try:
response = await client.get(url, params=params)
response.raise_for_status()
data = response.json()
results = data.get('results', [])
if results:
indent = " " * (depth + 1)
print(f"{indent}└─ 子页面数: {len(results)}")
for i, child in enumerate(results, 1):
child_id = child.get('id', 'N/A')
title = child.get('title', 'N/A')
print(f"{indent} {i}. ID: {child_id}, 标题: {title}")
# 检查是否还有更多嵌套
if depth < 2:
await check_grandchildren(client, base_url, child_id, depth + 1)
except Exception as e:
indent = " " * (depth + 1)
print(f"{indent}└─ 获取失败: {e}")
async def main():
"""主函数"""
# 检查 2025.06 页面 (ID: 137446576)
page_id = "137446576"
print(f"开始检查页面 {page_id} (2025.06) 的结构...")
await check_page_children(page_id)
if __name__ == "__main__":
asyncio.run(main())