added support for rezeptsuite.de imports
This commit is contained in:
@ -126,6 +126,8 @@ class IngredientParser:
|
|||||||
amount = 0
|
amount = 0
|
||||||
unit = None
|
unit = None
|
||||||
note = ''
|
note = ''
|
||||||
|
if x.strip() == '':
|
||||||
|
return amount, unit, note
|
||||||
|
|
||||||
did_check_frac = False
|
did_check_frac = False
|
||||||
end = 0
|
end = 0
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import base64
|
||||||
|
from io import BytesIO
|
||||||
from xml import etree
|
from xml import etree
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -5,54 +7,65 @@ from lxml import etree
|
|||||||
from cookbook.helper.ingredient_parser import IngredientParser
|
from cookbook.helper.ingredient_parser import IngredientParser
|
||||||
from cookbook.helper.recipe_url_import import parse_time, parse_servings, parse_servings_text
|
from cookbook.helper.recipe_url_import import parse_time, parse_servings, parse_servings_text
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
from cookbook.models import Ingredient, Recipe, Step
|
from cookbook.models import Ingredient, Recipe, Step, Keyword
|
||||||
|
|
||||||
|
|
||||||
class Rezeptsuitede(Integration):
|
class Rezeptsuitede(Integration):
|
||||||
|
|
||||||
def split_recipe_file(self, file):
|
def split_recipe_file(self, file):
|
||||||
xml_file = etree.parse(file).getroot().getchildren()
|
return etree.parse(file).getroot().getchildren()
|
||||||
recipe_list = xml_file.find('recipe')
|
|
||||||
return recipe_list
|
|
||||||
|
|
||||||
def get_recipe_from_file(self, file):
|
def get_recipe_from_file(self, file):
|
||||||
recipe_xml = file
|
recipe_xml = file
|
||||||
|
|
||||||
recipe = Recipe.objects.create(
|
recipe = Recipe.objects.create(
|
||||||
name=recipe_xml.find('title').text.strip(),
|
name=recipe_xml.find('head').attrib['title'].strip(),
|
||||||
created_by=self.request.user, internal=True, space=self.request.space)
|
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:
|
if recipe_xml.find('head').attrib['servingtype']:
|
||||||
recipe.servings = parse_servings(recipe_xml.find('servingtype').text.strip())
|
recipe.servings = parse_servings(recipe_xml.find('head').attrib['servingtype'].strip())
|
||||||
recipe.servings_text = parse_servings_text(recipe_xml.find('servingtype').text.strip())
|
recipe.servings_text = parse_servings_text(recipe_xml.find('head').attrib['servingtype'].strip())
|
||||||
|
|
||||||
if recipe_xml.find('description') is not None: # description is a list of <li>'s with text
|
if recipe_xml.find('remark') is not None: # description is a list of <li>'s with text
|
||||||
if len(recipe_xml.find('description')) > 0:
|
if recipe_xml.find('remark').find('line') is not None:
|
||||||
recipe.description = recipe_xml.find('description')[0].text[:512]
|
recipe.description = recipe_xml.find('remark').find('line').text[:512]
|
||||||
|
|
||||||
for step in recipe_xml.find('step'):
|
for prep in recipe_xml.findall('preparation'):
|
||||||
if step.text:
|
try:
|
||||||
|
if prep.find('step').text:
|
||||||
step = Step.objects.create(
|
step = Step.objects.create(
|
||||||
instruction=step.text.strip(), space=self.request.space,
|
instruction=prep.find('step').text.strip(), space=self.request.space,
|
||||||
)
|
)
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
ingredient_parser = IngredientParser(self.request, True)
|
ingredient_parser = IngredientParser(self.request, True)
|
||||||
|
|
||||||
if recipe_xml.find('ingredient'):
|
if recipe_xml.find('part').find('ingredient') is not None:
|
||||||
ingredient_step = recipe.steps.first()
|
ingredient_step = recipe.steps.first()
|
||||||
if ingredient_step is None:
|
if ingredient_step is None:
|
||||||
ingredient_step = Step.objects.create(space=self.request.space, instruction='')
|
ingredient_step = Step.objects.create(space=self.request.space, instruction='')
|
||||||
|
|
||||||
for ingredient in recipe_xml.find('ingredient'):
|
for ingredient in recipe_xml.find('part').findall('ingredient'):
|
||||||
f = ingredient_parser.get_food(ingredient.attrib['item'])
|
f = ingredient_parser.get_food(ingredient.attrib['item'])
|
||||||
u = ingredient_parser.get_unit(ingredient.attrib['unit'])
|
u = ingredient_parser.get_unit(ingredient.attrib['unit'])
|
||||||
ingredient_step.ingredients.add(Ingredient.objects.create(
|
amount, unit, note = ingredient_parser.parse_amount(ingredient.attrib['qty'])
|
||||||
food=f, unit=u, amount=ingredient.attrib['qty'], original_text=ingredient.text.strip(), space=self.request.space,
|
ingredient_step.ingredients.add(Ingredient.objects.create(food=f, unit=u, amount=amount, space=self.request.space, ))
|
||||||
))
|
|
||||||
|
try:
|
||||||
|
k, created = Keyword.objects.get_or_create(name=recipe_xml.find('head').find('cat').text.strip(), space=self.request.space)
|
||||||
|
recipe.keywords.add(k)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.import_recipe_image(recipe, BytesIO(base64.b64decode(recipe_xml.find('head').find('picbin').text)), filetype='.jpeg')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
|
||||||
def get_file_from_recipe(self, recipe):
|
def get_file_from_recipe(self, recipe):
|
||||||
|
@ -31,6 +31,7 @@ Overview of the capabilities of the different integrations.
|
|||||||
| ChefTap | ✔️ | ❌ | ❌ |
|
| ChefTap | ✔️ | ❌ | ❌ |
|
||||||
| Pepperplate | ✔️ | ⌚ | ❌ |
|
| Pepperplate | ✔️ | ⌚ | ❌ |
|
||||||
| RecipeSage | ✔️ | ✔️ | ✔️ |
|
| RecipeSage | ✔️ | ✔️ | ✔️ |
|
||||||
|
| Rezeptsuite.de | ✔️ | ❌ | ✔️ |
|
||||||
| Domestica | ✔️ | ⌚ | ✔️ |
|
| Domestica | ✔️ | ⌚ | ✔️ |
|
||||||
| MealMaster | ✔️ | ❌ | ❌ |
|
| MealMaster | ✔️ | ❌ | ❌ |
|
||||||
| RezKonv | ✔️ | ❌ | ❌ |
|
| RezKonv | ✔️ | ❌ | ❌ |
|
||||||
@ -233,6 +234,9 @@ Cookmate allows you to export a `.mcb` file which you can simply upload to tando
|
|||||||
## RecetteTek
|
## RecetteTek
|
||||||
RecetteTek exports are `.rtk` files which can simply be uploaded to tandoor to import all your recipes.
|
RecetteTek exports are `.rtk` files which can simply be uploaded to tandoor to import all your recipes.
|
||||||
|
|
||||||
|
## Rezeptsuite.de
|
||||||
|
Rezeptsuite.de exports are `.xml` files which can simply be uploaded to tandoor to import all your recipes.
|
||||||
|
|
||||||
## Melarecipes
|
## Melarecipes
|
||||||
|
|
||||||
Melarecipes provides multiple export formats but only the `MelaRecipes` format can export the complete collection.
|
Melarecipes provides multiple export formats but only the `MelaRecipes` format can export the complete collection.
|
||||||
|
Reference in New Issue
Block a user