diff --git a/cookbook/forms.py b/cookbook/forms.py index 626f2d12..1c1a90c0 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -154,6 +154,7 @@ class ImportExportBase(forms.Form): COOKBOOKAPP = 'COOKBOOKAPP' COPYMETHAT = 'COPYMETHAT' COOKMATE = 'COOKMATE' + REZEPTSUITEDE = 'REZEPTSUITEDE' PDF = 'PDF' type = forms.ChoiceField(choices=( @@ -162,7 +163,7 @@ class ImportExportBase(forms.Form): (PEPPERPLATE, 'Pepperplate'), (RECETTETEK, 'RecetteTek'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'), (MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'), (OPENEATS, 'Openeats'), (RECIPEKEEPER, 'Recipe Keeper'), (PLANTOEAT, 'Plantoeat'), (COOKBOOKAPP, 'CookBookApp'), (COPYMETHAT, 'CopyMeThat'), (PDF, 'PDF'), (MELARECIPES, 'Melarecipes'), - (COOKMATE, 'Cookmate') + (COOKMATE, 'Cookmate'), (REZEPTSUITEDE, 'Recipesuite.de') )) diff --git a/cookbook/integration/integration.py b/cookbook/integration/integration.py index b54e7e56..dbe3d667 100644 --- a/cookbook/integration/integration.py +++ b/cookbook/integration/integration.py @@ -1,16 +1,12 @@ -import time +import traceback import datetime -import json import traceback import uuid -from io import BytesIO, StringIO +from io import BytesIO from zipfile import BadZipFile, ZipFile -import lxml -from django.core.cache import cache -import datetime - from bs4 import Tag +from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist from django.core.files import File from django.db import IntegrityError @@ -20,8 +16,7 @@ from django.utils.translation import gettext as _ from django_scopes import scope from lxml import etree -from cookbook.forms import ImportExportBase -from cookbook.helper.image_processing import get_filetype, handle_image +from cookbook.helper.image_processing import handle_image from cookbook.models import Keyword, Recipe from recipes.settings import DEBUG from recipes.settings import EXPORT_FILE_CACHE_DURATION @@ -182,7 +177,7 @@ class Integration: traceback.print_exc() self.handle_exception(e, log=il, message=f'-------------------- \nERROR \n{e}\n--------------------\n') 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']) il.total_recipes += len(data_list) for d in data_list: diff --git a/cookbook/integration/rezeptsuitede.py b/cookbook/integration/rezeptsuitede.py new file mode 100644 index 00000000..2c05ccaf --- /dev/null +++ b/cookbook/integration/rezeptsuitede.py @@ -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