{
"event": "PreToolUse",
"tool_name": "Bash",
"tool_input": {
"command": "python3 << 'EOF'\nimport json\nimport re\nimport mariadb\nimport os\n\n# DB connection\nconn = mariadb.connect(\n host=\"localhost\",\n user=\"root\",\n password=os.environ.get(\"MARIADB_ROOT_PASSWORD\", \"v8mFLmkF2fth_r\"),\n database=\"ki_system\"\n)\ncursor = conn.cursor(dictionary=True)\n\n# Load docs to update\nwith open('\/tmp\/docs_to_update.json', 'r') as f:\n docs_to_update = json.load(f)\n\nupdated = 0\nskipped = 0\n\nfor doc in docs_to_update:\n doc_id = doc['id']\n created = doc['created']\n updated_date = doc['updated']\n \n # Get current content\n cursor.execute(\"SELECT content FROM dokumentation WHERE id = %s\", (doc_id,))\n row = cursor.fetchone()\n if not row:\n skipped += 1\n continue\n \n content = row['content']\n \n # Skip if already has date\n if 'Erstellt:<\/strong>' in content or 'Aktualisiert:<\/strong>' in content:\n skipped += 1\n continue\n \n # Create date header\n date_header = f'\\n<p class=\"doc-meta\"><strong>Erstellt:<\/strong> {created} | <strong>Aktualisiert:<\/strong> {updated_date}<\/p>\\n'\n \n # Insert after <\/h1>\n if '<\/h1>' in content:\n new_content = content.replace('<\/h1>', '<\/h1>' + date_header, 1)\n elif '<h1>' in content:\n # Find closing of h1\n new_content = re.sub(r'(<\/h1>)', r'\\1' + date_header, content, count=1)\n else:\n # No h1, add at start\n new_content = date_header + content\n \n # Update in DB\n cursor.execute(\n \"UPDATE dokumentation SET content = %s, updated_at = NOW() WHERE id = %s\",\n (new_content, doc_id)\n )\n updated += 1\n\nconn.commit()\ncursor.close()\nconn.close()\n\nprint(f\"Aktualisiert: {updated}\")\nprint(f\"Übersprungen: {skipped}\")\nEOF",
"description": "Add date headers to all docs"
}
}