add RecipeKeeper as an import/export method
This commit is contained in:
@ -112,6 +112,7 @@ class ImportExportBase(forms.Form):
|
|||||||
SAFRON = 'SAFRON'
|
SAFRON = 'SAFRON'
|
||||||
CHEFTAP = 'CHEFTAP'
|
CHEFTAP = 'CHEFTAP'
|
||||||
PEPPERPLATE = 'PEPPERPLATE'
|
PEPPERPLATE = 'PEPPERPLATE'
|
||||||
|
RECIPEKEEPER = 'RECIPEKEEPER'
|
||||||
RECIPESAGE = 'RECIPESAGE'
|
RECIPESAGE = 'RECIPESAGE'
|
||||||
DOMESTICA = 'DOMESTICA'
|
DOMESTICA = 'DOMESTICA'
|
||||||
MEALMASTER = 'MEALMASTER'
|
MEALMASTER = 'MEALMASTER'
|
||||||
@ -120,7 +121,7 @@ class ImportExportBase(forms.Form):
|
|||||||
type = forms.ChoiceField(choices=(
|
type = forms.ChoiceField(choices=(
|
||||||
(DEFAULT, _('Default')), (PAPRIKA, 'Paprika'), (NEXTCLOUD, 'Nextcloud Cookbook'),
|
(DEFAULT, _('Default')), (PAPRIKA, 'Paprika'), (NEXTCLOUD, 'Nextcloud Cookbook'),
|
||||||
(MEALIE, 'Mealie'), (CHOWDOWN, 'Chowdown'), (SAFRON, 'Safron'), (CHEFTAP, 'ChefTap'),
|
(MEALIE, 'Mealie'), (CHOWDOWN, 'Chowdown'), (SAFRON, 'Safron'), (CHEFTAP, 'ChefTap'),
|
||||||
(PEPPERPLATE, 'Pepperplate'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
|
(PEPPERPLATE, 'Pepperplate'), (RECIPEKEEPER, 'Recipe Keeper'), (RECIPESAGE, 'Recipe Sage'), (DOMESTICA, 'Domestica'),
|
||||||
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'),
|
(MEALMASTER, 'MealMaster'), (REZKONV, 'RezKonv'),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
59
cookbook/integration/recipekeeper.py
Normal file
59
cookbook/integration/recipekeeper.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||||
|
from cookbook.integration.integration import Integration
|
||||||
|
from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeKeeper(Integration):
|
||||||
|
|
||||||
|
def import_file_name_filter(self, zip_info_object):
|
||||||
|
return re.match(r'^recipes.html$', zip_info_object.filename)
|
||||||
|
|
||||||
|
def get_recipe_from_file(self, file):
|
||||||
|
source_url = ''
|
||||||
|
|
||||||
|
ingredient_mode = 0
|
||||||
|
|
||||||
|
ingredients = []
|
||||||
|
directions = []
|
||||||
|
for i, fl in enumerate(file.readlines(), start=0):
|
||||||
|
line = fl.decode("utf-8")
|
||||||
|
if i == 0:
|
||||||
|
title = line.strip()
|
||||||
|
else:
|
||||||
|
if line.startswith('https:') or line.startswith('http:'):
|
||||||
|
source_url = line.strip()
|
||||||
|
else:
|
||||||
|
if ingredient_mode == 1 and len(line.strip()) == 0:
|
||||||
|
ingredient_mode = 2
|
||||||
|
if re.match(r'^([0-9])[^.](.)*$', line) and ingredient_mode < 2:
|
||||||
|
ingredient_mode = 1
|
||||||
|
ingredients.append(line.strip())
|
||||||
|
else:
|
||||||
|
directions.append(line.strip())
|
||||||
|
|
||||||
|
recipe = Recipe.objects.create(name=title, created_by=self.request.user, internal=True, space=self.request.space, )
|
||||||
|
|
||||||
|
step = Step.objects.create(instruction='\n'.join(directions))
|
||||||
|
|
||||||
|
if source_url != '':
|
||||||
|
step.instruction += '\n' + source_url
|
||||||
|
step.save()
|
||||||
|
|
||||||
|
for ingredient in ingredients:
|
||||||
|
if len(ingredient.strip()) > 0:
|
||||||
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
|
f = get_food(ingredient, self.request.space)
|
||||||
|
u = get_unit(unit, self.request.space)
|
||||||
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
return recipe
|
||||||
|
|
||||||
|
def get_file_from_recipe(self, recipe):
|
||||||
|
raise NotImplementedError('Method not implemented in storage integration')
|
@ -19,6 +19,7 @@ from cookbook.integration.mealie import Mealie
|
|||||||
from cookbook.integration.mealmaster import MealMaster
|
from cookbook.integration.mealmaster import MealMaster
|
||||||
from cookbook.integration.nextcloud_cookbook import NextcloudCookbook
|
from cookbook.integration.nextcloud_cookbook import NextcloudCookbook
|
||||||
from cookbook.integration.paprika import Paprika
|
from cookbook.integration.paprika import Paprika
|
||||||
|
from cookbook.integration.recipekeeper import RecipeKeeper
|
||||||
from cookbook.integration.recipesage import RecipeSage
|
from cookbook.integration.recipesage import RecipeSage
|
||||||
from cookbook.integration.rezkonv import RezKonv
|
from cookbook.integration.rezkonv import RezKonv
|
||||||
from cookbook.integration.safron import Safron
|
from cookbook.integration.safron import Safron
|
||||||
@ -44,6 +45,8 @@ def get_integration(request, export_type):
|
|||||||
return Pepperplate(request, export_type)
|
return Pepperplate(request, export_type)
|
||||||
if export_type == ImportExportBase.DOMESTICA:
|
if export_type == ImportExportBase.DOMESTICA:
|
||||||
return Domestica(request, export_type)
|
return Domestica(request, export_type)
|
||||||
|
if export_type == ImportExportBase.RECIPEKEEPER:
|
||||||
|
return RecipeKeeper(request, export_type)
|
||||||
if export_type == ImportExportBase.RECIPESAGE:
|
if export_type == ImportExportBase.RECIPESAGE:
|
||||||
return RecipeSage(request, export_type)
|
return RecipeSage(request, export_type)
|
||||||
if export_type == ImportExportBase.REZKONV:
|
if export_type == ImportExportBase.REZKONV:
|
||||||
|
Reference in New Issue
Block a user