from pathlib import Path p = Path('/opt/tylorindar-safelink/main.py') t = p.read_text(encoding='utf-8') t = t.replace('@app.head("/{code}")\n@app.post("/api/v1/auto-enroll")', '@app.post("/api/v1/auto-enroll")', 1) old = '@app.get("/{code}")\nasync def redirect_shortlink' new = '@app.head("/{code}")\n@app.get("/{code}")\nasync def redirect_shortlink' if old in t: t = t.replace(old, new, 1) p.write_text(t, encoding='utf-8') print('head restored') else: print('redirect marker missing')