wip rezeptsuitede importer
This commit is contained in:
parent
9ad9fe275d
commit
f47470a9ad
@ -154,6 +154,7 @@ class ImportExportBase(forms.Form):
|
|||||||
COOKBOOKAPP = 'COOKBOOKAPP'
|
COOKBOOKAPP = 'COOKBOOKAPP'
|
||||||
COPYMETHAT = 'COPYMETHAT'
|
COPYMETHAT = 'COPYMETHAT'
|
||||||
COOKMATE = 'COOKMATE'
|
COOKMATE = 'COOKMATE'
|
||||||
|
REZEPTSUITEDE = 'REZEPTSUITEDE'
|
||||||
PDF = 'PDF'
|
PDF = 'PDF'
|
||||||
|
|
||||||
type = forms.ChoiceField(choices=(
|
type = forms.ChoiceField(choices=(
|
||||||
@ -162,7 +163,7 @@ class ImportExportBase(forms.Form):
|
|||||||
(PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
|
(PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
|
||||||
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'), (OPENEATS, 'Openeats'), (RECIPEKEEPER, 'Recipe Keeper'),
|
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'), (OPENEATS, 'Openeats'), (RECIPEKEEPER, 'Recipe Keeper'),
|
||||||
(PLANTOEAT, 'Plantoeat'), (COOKBOOKAPP, 'CookBookApp'), (COPYMETHAT, 'CopyMeThat'), (PDF, 'PDF'), (MELARECIPES, 'Melarecipes'),
|
(PLANTOEAT, 'Plantoeat'), (COOKBOOKAPP, 'CookBookApp'), (COPYMETHAT, 'CopyMeThat'), (PDF, 'PDF'), (MELARECIPES, 'Melarecipes'),
|
||||||
(COOKMATE, 'Cookmate')
|
(COOKMATE, 'Cookmate'), (REZEPTSUITEDE, 'Recipesuite.de')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
import time
|
import traceback
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
import traceback
|
import traceback
|
||||||
import uuid
|
import uuid
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO
|
||||||
from zipfile import BadZipFile, ZipFile
|
from zipfile import BadZipFile, ZipFile
|
||||||
|
|
||||||
import lxml
|
|
||||||
from django.core.cache import cache
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from bs4 import Tag
|
from bs4 import Tag
|
||||||
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
@ -20,8 +16,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django_scopes import scope
|
from django_scopes import scope
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
from cookbook.forms import ImportExportBase
|
from cookbook.helper.image_processing import handle_image
|
||||||
from cookbook.helper.image_processing import get_filetype, handle_image
|
|
||||||
from cookbook.models import Keyword, Recipe
|
from cookbook.models import Keyword, Recipe
|
||||||
from recipes.settings import DEBUG
|
from recipes.settings import DEBUG
|
||||||
from recipes.settings import EXPORT_FILE_CACHE_DURATION
|
from recipes.settings import EXPORT_FILE_CACHE_DURATION
|
||||||
@ -182,7 +177,7 @@ class Integration:
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.handle_exception(e, log=il, message=f'-------------------- \nERROR \n{e}\n--------------------\n')
|
self.handle_exception(e, log=il, message=f'-------------------- \nERROR \n{e}\n--------------------\n')
|
||||||
import_zip.close()
|
import_zip.close()
|
||||||
elif '.json' in f['name'] or '.txt' in f['name'] or '.mmf' in f['name'] or '.rk' in f['name'] or '.melarecipe' in f['name']:
|
elif '.json' in f['name'] or '.xml' in f['name'] or '.txt' in f['name'] or '.mmf' in f['name'] or '.rk' in f['name'] or '.melarecipe' in f['name']:
|
||||||
data_list = self.split_recipe_file(f['file'])
|
data_list = self.split_recipe_file(f['file'])
|
||||||
il.total_recipes += len(data_list)
|
il.total_recipes += len(data_list)
|
||||||
for d in data_list:
|
for d in data_list:
|
||||||
|
59
cookbook/integration/rezeptsuitede.py
Normal file
59
cookbook/integration/rezeptsuitede.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
from xml import etree
|
||||||
|
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from cookbook.helper.ingredient_parser import IngredientParser
|
||||||
|
from cookbook.helper.recipe_url_import import parse_time, parse_servings, parse_servings_text
|
||||||
|
from cookbook.integration.integration import Integration
|
||||||
|
from cookbook.models import Ingredient, Recipe, Step
|
||||||
|
|
||||||
|
|
||||||
|
class Rezeptsuitede(Integration):
|
||||||
|
|
||||||
|
def split_recipe_file(self, file):
|
||||||
|
xml_file = etree.parse(file).getroot().getchildren()
|
||||||
|
recipe_list = xml_file.find('recipe')
|
||||||
|
return recipe_list
|
||||||
|
|
||||||
|
def get_recipe_from_file(self, file):
|
||||||
|
recipe_xml = file
|
||||||
|
|
||||||
|
recipe = Recipe.objects.create(
|
||||||
|
name=recipe_xml.find('title').text.strip(),
|
||||||
|
created_by=self.request.user, internal=True, space=self.request.space)
|
||||||
|
|
||||||
|
if recipe_xml.find('servingtype') is not None and recipe_xml.find('servingtype').text is not None:
|
||||||
|
recipe.servings = parse_servings(recipe_xml.find('servingtype').text.strip())
|
||||||
|
recipe.servings_text = parse_servings_text(recipe_xml.find('servingtype').text.strip())
|
||||||
|
|
||||||
|
if recipe_xml.find('description') is not None: # description is a list of <li>'s with text
|
||||||
|
if len(recipe_xml.find('description')) > 0:
|
||||||
|
recipe.description = recipe_xml.find('description')[0].text[:512]
|
||||||
|
|
||||||
|
for step in recipe_xml.find('step'):
|
||||||
|
if step.text:
|
||||||
|
step = Step.objects.create(
|
||||||
|
instruction=step.text.strip(), space=self.request.space,
|
||||||
|
)
|
||||||
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
ingredient_parser = IngredientParser(self.request, True)
|
||||||
|
|
||||||
|
if recipe_xml.find('ingredient'):
|
||||||
|
ingredient_step = recipe.steps.first()
|
||||||
|
if ingredient_step is None:
|
||||||
|
ingredient_step = Step.objects.create(space=self.request.space, instruction='')
|
||||||
|
|
||||||
|
for ingredient in recipe_xml.find('ingredient'):
|
||||||
|
f = ingredient_parser.get_food(ingredient.attrib['item'])
|
||||||
|
u = ingredient_parser.get_unit(ingredient.attrib['unit'])
|
||||||
|
ingredient_step.ingredients.add(Ingredient.objects.create(
|
||||||
|
food=f, unit=u, amount=ingredient.attrib['qty'], original_text=ingredient.text.strip(), space=self.request.space,
|
||||||
|
))
|
||||||
|
|
||||||
|
recipe.save()
|
||||||
|
|
||||||
|
return recipe
|
||||||
|
|
||||||
|
def get_file_from_recipe(self, recipe):
|
||||||
|
raise NotImplementedError('Method not implemented in storage integration')
|
@ -1306,6 +1306,8 @@ def import_files(request):
|
|||||||
return Response({'import_id': il.pk}, status=status.HTTP_200_OK)
|
return Response({'import_id': il.pk}, status=status.HTTP_200_OK)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
return Response({'error': True, 'msg': _('Importing is not implemented for this provider')}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({'error': True, 'msg': _('Importing is not implemented for this provider')}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
else:
|
||||||
|
return Response({'error': True, 'msg': form.errors}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
def get_recipe_provider(recipe):
|
def get_recipe_provider(recipe):
|
||||||
|
@ -31,6 +31,7 @@ from cookbook.integration.plantoeat import Plantoeat
|
|||||||
from cookbook.integration.recettetek import RecetteTek
|
from cookbook.integration.recettetek import RecetteTek
|
||||||
from cookbook.integration.recipekeeper import RecipeKeeper
|
from cookbook.integration.recipekeeper import RecipeKeeper
|
||||||
from cookbook.integration.recipesage import RecipeSage
|
from cookbook.integration.recipesage import RecipeSage
|
||||||
|
from cookbook.integration.rezeptsuitede import Rezeptsuitede
|
||||||
from cookbook.integration.rezkonv import RezKonv
|
from cookbook.integration.rezkonv import RezKonv
|
||||||
from cookbook.integration.saffron import Saffron
|
from cookbook.integration.saffron import Saffron
|
||||||
from cookbook.models import ExportLog, ImportLog, Recipe, UserPreference
|
from cookbook.models import ExportLog, ImportLog, Recipe, UserPreference
|
||||||
@ -80,6 +81,8 @@ def get_integration(request, export_type):
|
|||||||
return MelaRecipes(request, export_type)
|
return MelaRecipes(request, export_type)
|
||||||
if export_type == ImportExportBase.COOKMATE:
|
if export_type == ImportExportBase.COOKMATE:
|
||||||
return Cookmate(request, export_type)
|
return Cookmate(request, export_type)
|
||||||
|
if export_type == ImportExportBase.REZEPTSUITEDE:
|
||||||
|
return Rezeptsuitede(request, export_type)
|
||||||
|
|
||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
|
@ -21,4 +21,5 @@ export const INTEGRATIONS = [
|
|||||||
{id: 'RECIPESAGE', name: "Recipesage", import: true, export: true, help_url: 'https://docs.tandoor.dev/features/import_export/#recipesage'},
|
{id: 'RECIPESAGE', name: "Recipesage", import: true, export: true, help_url: 'https://docs.tandoor.dev/features/import_export/#recipesage'},
|
||||||
{id: 'REZKONV', name: "Rezkonv", import: true, export: false, help_url: 'https://docs.tandoor.dev/features/import_export/#rezkonv'},
|
{id: 'REZKONV', name: "Rezkonv", import: true, export: false, help_url: 'https://docs.tandoor.dev/features/import_export/#rezkonv'},
|
||||||
{id: 'SAFRON', name: "Safron", import: true, export: true, help_url: 'https://docs.tandoor.dev/features/import_export/#safron'},
|
{id: 'SAFRON', name: "Safron", import: true, export: true, help_url: 'https://docs.tandoor.dev/features/import_export/#safron'},
|
||||||
|
{id: 'REZEPTSUITEDE', name: "Rezeptsuite.de", import: true, export: false, help_url: 'https://docs.tandoor.dev/features/import_export/#rezeptsuitede'},
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user