52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
from pathlib import Path
|
|
p=Path('/root/.openclaw/workspace/websites.yaml')
|
|
lines=p.read_text(encoding='utf-8').splitlines()
|
|
|
|
# Ensure hard route keywords contain inventory terms
|
|
hard_start=None
|
|
hard_end=None
|
|
for i,l in enumerate(lines):
|
|
if l.strip()=='- when_keywords:' and i>0 and 'hard_route_rules:' in lines[i-1]:
|
|
# first rule, skip
|
|
pass
|
|
for i,l in enumerate(lines):
|
|
if l.strip()=='- when_keywords:' and i+1 < len(lines) and lines[i+1].strip()=='- 销售数据':
|
|
hard_start=i
|
|
# find force_site_id line
|
|
for j in range(i+1,len(lines)):
|
|
if 'force_site_id: company-sales-db-analysis' in lines[j]:
|
|
hard_end=j
|
|
break
|
|
break
|
|
if hard_start is not None and hard_end is not None:
|
|
existing=set(l.strip().lstrip('-').strip() for l in lines[hard_start:hard_end] if l.strip().startswith('- '))
|
|
need=['库存','缺货','补货','安全库存']
|
|
insert_pos=hard_end
|
|
for kw in need:
|
|
if kw not in existing:
|
|
lines.insert(insert_pos, ' - '+kw)
|
|
insert_pos+=1
|
|
|
|
# Ensure site keywords contain inventory terms
|
|
site_kw_start=None
|
|
site_kw_end=None
|
|
for i,l in enumerate(lines):
|
|
if l.strip()=='keywords:' and i>0 and lines[i-1].strip()=='- 物流与安装协同分析':
|
|
site_kw_start=i
|
|
for j in range(i+1,len(lines)):
|
|
if lines[j].strip()=='login_required: false':
|
|
site_kw_end=j
|
|
break
|
|
break
|
|
if site_kw_start is not None and site_kw_end is not None:
|
|
existing=set(l.strip().lstrip('-').strip() for l in lines[site_kw_start:site_kw_end] if l.strip().startswith('- '))
|
|
need=['库存','缺货','补货','安全库存']
|
|
insert_pos=site_kw_end
|
|
for kw in need:
|
|
if kw not in existing:
|
|
lines.insert(insert_pos, ' - '+kw)
|
|
insert_pos+=1
|
|
|
|
p.write_text('\n'.join(lines)+'\n',encoding='utf-8')
|
|
print('updated',p)
|