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:
+17
-1
@@ -58,6 +58,18 @@ def _hash_password(password: str) -> str:
|
|||||||
return hashlib.sha256(password.encode("utf-8")).hexdigest()
|
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
|
# Routes
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -182,8 +194,12 @@ def scrape_url():
|
|||||||
real_ingredients = [i for i in data.get("ingredients", []) if "group" not in i]
|
real_ingredients = [i for i in data.get("ingredients", []) if "group" not in i]
|
||||||
if not real_ingredients:
|
if not real_ingredients:
|
||||||
warnings.append("A recept nem tartalmaz hozzávalókat.")
|
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.")
|
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,
|
return jsonify({"ok": True, "data": data, "duplicate": duplicate,
|
||||||
"tandoor_duplicate": tandoor_duplicate,
|
"tandoor_duplicate": tandoor_duplicate,
|
||||||
|
|||||||
Reference in New Issue
Block a user