Files
MoFin/archive/20260722-scripts-cleanup/add_hygiene_cron.py
T

45 lines
1.4 KiB
Python

import json, shutil, uuid
from datetime import datetime
jf = '/home/hmo/.hermes/profiles/position-analyst/cron/jobs.json'
shutil.copy(jf, jf + '.bak-20260720-hygiene')
d = json.load(open(jf))
is_list = isinstance(d, list)
jobs = d if is_list else d.get('jobs', [])
# 防重复
if any(j.get('script') == 'system_hygiene_audit.py' for j in jobs):
print('job already exists')
else:
job = {
"id": uuid.uuid4().hex[:12],
"name": "系统卫生审计-每周",
"prompt": "",
"skills": [],
"skill": None,
"model": None,
"provider": None,
"base_url": None,
"script": "system_hygiene_audit.py",
"no_agent": True,
"context_from": None,
"schedule": {"kind": "cron", "expr": "30 7 * * 1", "display": "30 7 * * 1"},
"schedule_display": "30 7 * * 1",
"repeat": {"times": None, "completed": 0},
"enabled": True,
"state": "scheduled",
"paused_at": None,
"paused_reason": None,
"created_at": datetime.now().isoformat(),
"next_run_at": "2026-07-21T07:30:00+08:00",
"last_run_at": None,
"last_status": None,
}
jobs.append(job)
if is_list:
json.dump(jobs, open(jf, 'w'), ensure_ascii=False, indent=2)
else:
d['jobs'] = jobs
json.dump(d, open(jf, 'w'), ensure_ascii=False, indent=2)
print('added job: 系统卫生审计-每周 (Mon 07:30)')
print('total jobs:', len(jobs))