[teamai] Push 1 resource(s) from root

This commit is contained in:
2026-09-10 16:51:20 +08:00
parent f3388c50e2
commit 766efe4076
15 changed files with 1284 additions and 0 deletions
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""创建方案页面,挂到「📋 方案库」目录下"""
import json, sys, os, argparse
import subprocess
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
SPACE_ID = os.environ.get('FEISHU_SPACE_ID', '7664817589230570761')
PLAN_PARENT = os.environ.get('FEISHU_PLAN_PARENT', 'LjXOwVZkriKmQwkjoixcnrSbnhd') # 📋 方案库
def get_token():
r = subprocess.run(['python3', os.path.join(SCRIPTS_DIR, 'init_token.py')],
capture_output=True, text=True)
return json.loads(r.stdout)['token']
def create_plan(title, content_file=None, parent=None):
import requests
token = get_token()
h = {'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json'}
parent = parent or PLAN_PARENT
# 检查同名节点是否已存在(避免重复创建)
r = requests.get(
f'https://open.feishu.cn/open-apis/wiki/v2/spaces/{SPACE_ID}/nodes',
params={'parent_node_token': parent}, headers=h
)
kids = r.json().get('data', {}).get('items', [])
for k in kids:
if k.get('title') == title:
print(json.dumps({'node_token': k['node_token'], 'obj_token': k.get('obj_token'), 'exists': True}))
return k
# 创建新节点
r = requests.post(
f'https://open.feishu.cn/open-apis/wiki/v2/spaces/{SPACE_ID}/nodes',
headers=h,
json={'obj_type': 'docx', 'node_type': 'origin', 'parent_node_token': parent, 'title': title}
)
data = r.json()
if data.get('code') != 0:
raise Exception(f"Create plan node failed: {data.get('msg')}")
node = data['data']['node']
print(json.dumps({'node_token': node['node_token'], 'obj_token': node['obj_token'], 'exists': False}))
# 写入内容
if content_file:
subprocess.run(
['python3', os.path.join(SCRIPTS_DIR, 'wiki_write.py'), '--node', node['node_token'], '--file', content_file],
check=True
)
return node
if __name__ == '__main__':
p = argparse.ArgumentParser(description='创建飞书方案库页面')
p.add_argument('--title', required=True, help='方案标题')
p.add_argument('--content', default=None, help='内容 markdown 文件路径')
p.add_argument('--parent', default=None, help='父节点 token(默认方案库)')
args = p.parse_args()
try:
create_plan(args.title, args.content, args.parent)
except Exception as e:
print(f'Error: {e}', file=sys.stderr)
sys.exit(1)