diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index c4ef38b79..dfbe30aa6 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -13,92 +13,70 @@ from django.utils.translation import gettext as _ from recipe_scrapers._utils import get_minutes, normalize_string -def find_recipe_json(ld_json, url, space): - ld_json['name'] = parse_name(ld_json['name']) +# def find_recipe_json(ld_json, url, space): +# ld_json['name'] = parse_name(ld_json['name']) - except AttributeError: - description = '' +# # some sites use ingredients instead of recipeIngredients +# if 'recipeIngredient' not in ld_json and 'ingredients' in ld_json: +# ld_json['recipeIngredient'] = ld_json['ingredients'] - if 'recipeIngredient' in ld_json: - ld_json['recipeIngredient'] = parse_ingredients(ld_json['recipeIngredient']) - else: - ld_json['recipeIngredient'] = "" +# if 'recipeIngredient' in ld_json: +# ld_json['recipeIngredient'] = parse_ingredients(ld_json['recipeIngredient']) +# else: +# ld_json['recipeIngredient'] = "" - try: - servings = scrape.yields() - servings = int(re.findall(r'\b\d+\b', servings)[0]) - except (AttributeError, ValueError, IndexError): - servings = 1 - recipe_json['servings'] = servings +# keywords = [] +# if 'keywords' in ld_json: +# keywords += listify_keywords(ld_json['keywords']) +# if 'recipeCategory' in ld_json: +# keywords += listify_keywords(ld_json['recipeCategory']) +# if 'recipeCuisine' in ld_json: +# keywords += listify_keywords(ld_json['recipeCuisine']) +# try: +# ld_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space) +# except TypeError: +# pass - try: - recipe_json['prepTime'] = get_minutes(scrape.schema.data.get("prepTime")) or 0 - except AttributeError: - recipe_json['prepTime'] = 0 - try: - recipe_json['cookTime'] = get_minutes(scrape.schema.data.get("cookTime")) or 0 - except AttributeError: - recipe_json['cookTime'] = 0 - if recipe_json['cookTime'] + recipe_json['prepTime'] == 0: - try: - recipe_json['prepTime'] = get_minutes(scrape.total_time()) or 0 - except AttributeError: - pass - keywords = [] - if 'keywords' in ld_json: - keywords += listify_keywords(ld_json['keywords']) - if 'recipeCategory' in ld_json: - keywords += listify_keywords(ld_json['recipeCategory']) - if 'recipeCuisine' in ld_json: - keywords += listify_keywords(ld_json['recipeCuisine']) - try: - ld_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space) - except TypeError: - pass +# if 'recipeInstructions' in ld_json: +# ld_json['recipeInstructions'] = parse_instructions(ld_json['recipeInstructions']) +# else: +# ld_json['recipeInstructions'] = "" - if 'recipeInstructions' in ld_json: - ld_json['recipeInstructions'] = parse_instructions(ld_json['recipeInstructions']) - else: - ld_json['recipeInstructions'] = "" +# if 'image' in ld_json: +# ld_json['image'] = parse_image(ld_json['image']) +# else: +# ld_json['image'] = "" - if url: - ld_json['recipeInstructions'] += "\nImported from " + url +# if 'description' in ld_json: +# ld_json['description'] = normalize_string(ld_json['description']) +# else: +# ld_json['description'] = "" - if 'image' in ld_json: - ld_json['image'] = parse_image(ld_json['image']) - else: - ld_json['image'] = "" +# if 'cookTime' in ld_json: +# ld_json['cookTime'] = parse_cooktime(ld_json['cookTime']) +# else: +# ld_json['cookTime'] = 0 - if 'description' in ld_json: - ld_json['description'] = normalize_string(ld_json['description']) - else: - ld_json['description'] = "" +# if 'prepTime' in ld_json: +# ld_json['prepTime'] = parse_cooktime(ld_json['prepTime']) +# else: +# ld_json['prepTime'] = 0 - if 'cookTime' in ld_json: - ld_json['cookTime'] = parse_cooktime(ld_json['cookTime']) - else: - ld_json['cookTime'] = 0 +# if 'servings' in ld_json: +# ld_json['servings'] = parse_servings(ld_json['servings']) +# elif 'recipeYield' in ld_json: +# ld_json['servings'] = parse_servings(ld_json['recipeYield']) +# else: +# ld_json['servings'] = 1 - if 'prepTime' in ld_json: - ld_json['prepTime'] = parse_cooktime(ld_json['prepTime']) - else: - ld_json['prepTime'] = 0 +# for key in list(ld_json): +# if key not in [ +# 'prepTime', 'cookTime', 'image', 'recipeInstructions', +# 'keywords', 'name', 'recipeIngredient', 'servings', 'description' +# ]: +# ld_json.pop(key, None) - if 'servings' in ld_json: - ld_json['servings'] = parse_servings(ld_json['servings']) - elif 'recipeYield' in ld_json: - ld_json['servings'] = parse_servings(ld_json['recipeYield']) - else: - ld_json['servings'] = 1 - - for key in list(ld_json): - if key not in [ - 'prepTime', 'cookTime', 'image', 'recipeInstructions', - 'keywords', 'name', 'recipeIngredient', 'servings', 'description' - ]: - ld_json.pop(key, None) - - return ld_json +# return ld_json def get_from_scraper(scrape, space):