import json, shutil REMOVE = { 'pa': ['MoFin 盘前中监控', 'MoFin 午后监控', '自选买入区提醒', '候选股自动推广-盘中'], 'default': ['持仓情报-盘中', '快速盯盘-15分钟', '价格监控-1分钟', 'PM-项目跟进'], } FILES = { 'pa': '/home/hmo/.hermes/profiles/position-analyst/cron/jobs.json', 'default': '/home/hmo/.hermes/cron/jobs.json', } for prof, jf in FILES.items(): shutil.copy(jf, jf + '.bak-20260720-disabled-cleanup') d = json.load(open(jf)) is_list = isinstance(d, list) jobs = d if is_list else d.get('jobs', []) removed = [j.get('name') for j in jobs if j.get('name') in REMOVE[prof]] kept = [j for j in jobs if j.get('name') not in REMOVE[prof]] if removed: if is_list: json.dump(kept, open(jf, 'w'), ensure_ascii=False, indent=2) else: d['jobs'] = kept json.dump(d, open(jf, 'w'), ensure_ascii=False, indent=2) print(f'{prof}: removed {removed}') # 剩余禁用任务 still_disabled = [j.get('name') for j in kept if not j.get('enabled', True)] print(f' remaining disabled: {still_disabled}') total = len(kept) print(f' total jobs now: {total}')