Files
teamai-global/skills/feishu-wiki-tools/scripts/wiki_delete.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

50 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""删除知识库节点(移到回收站)"""
import json, sys, os, argparse
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)
return json.loads(r.stdout)['token']
def delete_node(node_token):
import requests
token = get_token()
h = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}
# Get obj_token
r = requests.get(
'https://open.feishu.cn/open-apis/wiki/v2/spaces/get_node',
params={'token': node_token}, headers=h
)
nd = r.json()
if nd.get('code') != 0:
raise Exception(f"Get node failed: {nd.get('msg')}")
obj_token = nd['data']['node']['obj_token']
obj_type = nd['data']['node'].get('obj_type', 'docx')
# Delete via drive API(type 参数需与节点实际类型一致:docx/bitable/sheet 等)
r = requests.delete(
f'https://open.feishu.cn/open-apis/drive/v1/files/{obj_token}?type={obj_type}',
headers=h
)
data = r.json()
if data.get('code') != 0:
raise Exception(f"Delete failed: {data.get('msg')}")
return True
if __name__ == '__main__':
p = argparse.ArgumentParser()
p.add_argument('--node', required=True, help='Node token to delete')
args = p.parse_args()
try:
delete_node(args.node)
print('Deleted')
except Exception as e:
print(f'Error: {e}', file=sys.stderr)
sys.exit(1)