Files
teamai-global/skills/feishu-wiki-tools/scripts/wiki_list.py
T
NightStar 3d3dd79df0 Add 39 shared skills from local agent inventory
Sources: ~/.openclaw/skills, ~/.agents/skills, workshop-skills, workspace/skills
2026-09-10 16:54:57 +08:00

38 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""列出知识库节点,可选指定父节点"""
import json, sys, os
import subprocess
SPACE_ID = os.environ.get('FEISHU_SPACE_ID', '7664817589230570761')
def get_token():
r = subprocess.run(['python3', os.path.join(os.path.dirname(__file__), 'init_token.py')],
capture_output=True, text=True)
td = json.loads(r.stdout)
return td['token']
def list_nodes(parent_token=None):
import requests
token = get_token()
h = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}
url = f'https://open.feishu.cn/open-apis/wiki/v2/spaces/{SPACE_ID}/nodes'
params = {}
if parent_token:
params['parent_node_token'] = parent_token
r = requests.get(url, params=params, headers=h)
data = r.json()
if data.get('code') != 0:
raise Exception(f"API error: {data.get('msg')}")
return data['data']['items']
if __name__ == '__main__':
parent = sys.argv[1] if len(sys.argv) > 1 else None
try:
nodes = list_nodes(parent)
print(json.dumps(nodes, indent=2, ensure_ascii=False))
except Exception as e:
print(f'Error: {e}', file=sys.stderr)
sys.exit(1)