from pathlib import Path
p=Path('/opt/struktur/content-extraction/app.py')
s=p.read_text()
s=s.replace('def _build_search_url(*, q: str = "", tag: str = "", sort: str = "score", limit: str = "50"):', 'def _build_search_url(*, q: str = "", tag: str = "", sort: str = "score", limit: str = "50", exclude_customer_projects: str = "yes"):',1)
s=s.replace('''    if limit:\n        params["limit"] = limit\n    return "/?" + urlencode(params)\n''','''    if limit:\n        params["limit"] = limit\n    if exclude_customer_projects:\n        params["exclude_customer_projects"] = exclude_customer_projects\n    return "/?" + urlencode(params)\n''',1)
s=s.replace('def _render_search_page(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50"):', 'def _render_search_page(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50", exclude_customer_projects: str = "yes"):',1)
s=s.replace('''    if q:\n        results, search_info = db.search_videos(q, tag=tag, limit=limit_value, sort=sort)\n''','''    exclude_processed = (exclude_customer_projects or "yes").strip().lower() not in {"no", "0", "false"}\n    if q:\n        results, search_info = db.search_videos(q, tag=tag, limit=limit_value, sort=sort, exclude_customer_projects=exclude_processed)\n''',1)
s=s.replace('''        "build_search_url": _build_search_url,\n    })\n''','''        "build_search_url": _build_search_url,\n        "exclude_customer_projects": "yes" if exclude_processed else "no",\n    })\n''',1)
s=s.replace('def index(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50"):\n    return _render_search_page(request, q, tag, sort, limit)', 'def index(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50", exclude_customer_projects: str = "yes"):\n    return _render_search_page(request, q, tag, sort, limit, exclude_customer_projects)',1)
s=s.replace('def search(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50"):\n    return _render_search_page(request, q, tag, sort, limit)', 'def search(request: Request, q: str = "", tag: str = "", sort: str = "score", limit: str = "50", exclude_customer_projects: str = "yes"):\n    return _render_search_page(request, q, tag, sort, limit, exclude_customer_projects)',1)
p.write_text(s)
print('APP_PATCHED')