From 608039b7e40b783c78c258e439524c6d4109c06f Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 11 Jul 2022 14:46:54 +0200 Subject: [PATCH] cookbookapp importer more or less broken (more) --- cookbook/integration/cookbookapp.py | 9 ++++--- .../ImportResponseView/ImportResponseView.vue | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/cookbook/integration/cookbookapp.py b/cookbook/integration/cookbookapp.py index 7ff50ab62..46e6d7bf3 100644 --- a/cookbook/integration/cookbookapp.py +++ b/cookbook/integration/cookbookapp.py @@ -10,7 +10,7 @@ import validators import yaml from cookbook.helper.ingredient_parser import IngredientParser -from cookbook.helper.recipe_url_import import get_images_from_soup, iso_duration_to_minutes +from cookbook.helper.recipe_url_import import get_images_from_soup, iso_duration_to_minutes, get_from_scraper from cookbook.helper.scrapers.scrapers import text_scraper from cookbook.integration.integration import Integration from cookbook.models import Ingredient, Keyword, Recipe, Step @@ -25,9 +25,9 @@ class CookBookApp(Integration): recipe_html = file.getvalue().decode("utf-8") # recipe_json, recipe_tree, html_data, images = get_recipe_from_source(recipe_html, 'CookBookApp', self.request) - scrape = text_scraper(text=data) - recipe_json = helper.get_from_scraper(scrape, request) - images = list(dict.fromkeys(get_images_from_soup(scrape.soup, url))) + scrape = text_scraper(text=recipe_html) + recipe_json = get_from_scraper(scrape, self.request) + images = list(dict.fromkeys(get_images_from_soup(scrape.soup, None))) recipe = Recipe.objects.create( name=recipe_json['name'].strip(), @@ -45,6 +45,7 @@ class CookBookApp(Integration): except Exception: pass + step = Step.objects.create(instruction=recipe_json['recipeInstructions'], space=self.request.space, ) if 'nutrition' in recipe_json: diff --git a/vue/src/apps/ImportResponseView/ImportResponseView.vue b/vue/src/apps/ImportResponseView/ImportResponseView.vue index 9101e745b..e51b4b577 100644 --- a/vue/src/apps/ImportResponseView/ImportResponseView.vue +++ b/vue/src/apps/ImportResponseView/ImportResponseView.vue @@ -69,7 +69,9 @@ v-if="recipe.imported !== undefined && recipe.imported" target="_blank">{{ recipe.recipe_name - }} {{ recipe.recipe_name }} + }} {{ recipe.recipe_name }} {{ index + 1 }}

@@ -212,16 +214,19 @@ export default { } if (out.info !== '') { let items = out.info.split(/:(.*)/s)[1] - items = items.split(",") - out.duplicates_total = items.length - out.recipes.forEach((recipe) => { - recipe.imported = true - items.forEach((item) => { - if (recipe.recipe_name === item.trim()) { - recipe.imported = false - } + if (items !== undefined) { + items = items.split(",") + out.duplicates_total = items.length + out.recipes.forEach((recipe) => { + recipe.imported = true + items.forEach((item) => { + if (recipe.recipe_name === item.trim()) { + recipe.imported = false + } + }) }) - }) + } + } else { if (out.imported_total > 0) { out.recipes.forEach((recipe) => {