Skip to content

Commit

Permalink
make finding candidates for instructions more robust (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tantali authored Feb 21, 2025
1 parent a7202e8 commit 5f9fa7b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions recipe_scrapers/dagelijksekost.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ def levenshtein_distance(s1, s2):


def find_json(blocks):
res = []
for block in blocks:
if not block.string or "self.__next_f.push" not in block.string:
continue
start_idx = block.string.find('"f:')
start_idx = block.string.find(":[")
end_idx = block.string.rfind('"')
if start_idx == -1 or end_idx == -1 or start_idx >= end_idx:
continue
json_content = block.string[start_idx + 3 : end_idx]
json_content = block.string[start_idx + 1 : end_idx]
try:
unescaped_content = json_content.encode(
"latin-1", "backslashreplace"
).decode("unicode-escape")
return json.loads(unescaped_content)
res.extend(json.loads(unescaped_content))
except json.JSONDecodeError:
continue
return None
return res


def find_instructions(data):
Expand Down

0 comments on commit 5f9fa7b

Please sign in to comment.