Detect redirect-like instructions and show warning

When recipe instructions are just a link to another site (e.g.
"ide kattintva, a Kiskegyed oldalán találod"), display a warning
instead of silently accepting non-useful instruction text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 18:22:19 +01:00
parent baa63a43b2
commit 4467265168
+17 -1
View File
@@ -58,6 +58,18 @@ def _hash_password(password: str) -> str:
return hashlib.sha256(password.encode("utf-8")).hexdigest()
_REDIRECT_PATTERNS = ["ide kattintva", "oldalán találod", "teljes recept itt",
"kattints ide", "eredeti recept"]
def _is_redirect_instructions(instructions: list[str]) -> bool:
"""Check if instructions are just a redirect to another site."""
if len(instructions) > 2:
return False
text = " ".join(instructions).lower()
return any(p in text for p in _REDIRECT_PATTERNS)
# ---------------------------------------------------------------------------
# Routes
# ---------------------------------------------------------------------------
@@ -182,8 +194,12 @@ def scrape_url():
real_ingredients = [i for i in data.get("ingredients", []) if "group" not in i]
if not real_ingredients:
warnings.append("A recept nem tartalmaz hozzávalókat.")
if not data.get("instructions"):
instructions = data.get("instructions", [])
if not instructions:
warnings.append("A recept nem tartalmaz elkészítési lépéseket.")
elif _is_redirect_instructions(instructions):
warnings.append("Az elkészítés egy másik oldalra mutat. "
"A recept valószínűleg nem tartalmaz valódi lépéseket.")
return jsonify({"ok": True, "data": data, "duplicate": duplicate,
"tandoor_duplicate": tandoor_duplicate,