added openeats importer
This commit is contained in:
parent
a0b6261275
commit
99fbc5e97c
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
@ -10,8 +11,61 @@ from cookbook.models import Recipe, Step, Food, Unit, Ingredient
|
|||||||
class OpenEats(Integration):
|
class OpenEats(Integration):
|
||||||
|
|
||||||
def get_recipe_from_file(self, file):
|
def get_recipe_from_file(self, file):
|
||||||
|
recipe = Recipe.objects.create(name=file['name'].strip(), created_by=self.request.user, internal=True,
|
||||||
|
servings=file['servings'], space=self.request.space, waiting_time=file['cook_time'], working_time=file['prep_time'])
|
||||||
|
|
||||||
return None
|
instructions = ''
|
||||||
|
if file["info"] != '':
|
||||||
|
instructions += file["info"]
|
||||||
|
|
||||||
|
if file["directions"] != '':
|
||||||
|
instructions += file["directions"]
|
||||||
|
|
||||||
|
if file["source"] != '':
|
||||||
|
instructions += file["source"]
|
||||||
|
|
||||||
|
step = Step.objects.create(instruction=instructions)
|
||||||
|
|
||||||
|
for ingredient in file['ingredients']:
|
||||||
|
f = get_food(ingredient['food'], self.request.space)
|
||||||
|
u = get_unit(ingredient['unit'], self.request.space)
|
||||||
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
|
food=f, unit=u, amount=ingredient['amount']
|
||||||
|
))
|
||||||
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
return recipe
|
||||||
|
|
||||||
|
def split_recipe_file(self, file):
|
||||||
|
recipe_json = json.loads(file.read())
|
||||||
|
recipe_dict = {}
|
||||||
|
ingredient_group_dict = {}
|
||||||
|
|
||||||
|
for o in recipe_json:
|
||||||
|
if o['model'] == 'recipe.recipe':
|
||||||
|
recipe_dict[o['pk']] = {
|
||||||
|
'name': o['fields']['title'],
|
||||||
|
'info': o['fields']['info'],
|
||||||
|
'directions': o['fields']['directions'],
|
||||||
|
'source': o['fields']['source'],
|
||||||
|
'prep_time': o['fields']['prep_time'],
|
||||||
|
'cook_time': o['fields']['cook_time'],
|
||||||
|
'servings': o['fields']['servings'],
|
||||||
|
'ingredients': [],
|
||||||
|
}
|
||||||
|
if o['model'] == 'ingredient.ingredientgroup':
|
||||||
|
ingredient_group_dict[o['pk']] = o['fields']['recipe']
|
||||||
|
|
||||||
|
for o in recipe_json:
|
||||||
|
if o['model'] == 'ingredient.ingredient':
|
||||||
|
ingredient = {
|
||||||
|
'food': o['fields']['title'],
|
||||||
|
'unit': o['fields']['measurement'],
|
||||||
|
'amount': round(o['fields']['numerator'] / o['fields']['denominator'], 2),
|
||||||
|
}
|
||||||
|
recipe_dict[ingredient_group_dict[o['fields']['ingredient_group']]]['ingredients'].append(ingredient)
|
||||||
|
|
||||||
|
return list(recipe_dict.values())
|
||||||
|
|
||||||
def get_file_from_recipe(self, recipe):
|
def get_file_from_recipe(self, recipe):
|
||||||
raise NotImplementedError('Method not implemented in storage integration')
|
raise NotImplementedError('Method not implemented in storage integration')
|
||||||
|
@ -34,6 +34,7 @@ Overview of the capabilities of the different integrations.
|
|||||||
| Domestica | ✔️ | ⌚ | ✔️ |
|
| Domestica | ✔️ | ⌚ | ✔️ |
|
||||||
| MealMaster | ✔️ | ❌ | ❌ |
|
| MealMaster | ✔️ | ❌ | ❌ |
|
||||||
| RezKonv | ✔️ | ❌ | ❌ |
|
| RezKonv | ✔️ | ❌ | ❌ |
|
||||||
|
| OpenEats | ✔️ | ❌ | ⌚ |
|
||||||
|
|
||||||
✔ = implemented, ❌ = not implemented and not possible/planned, ⌚ = not yet implemented
|
✔ = implemented, ❌ = not implemented and not possible/planned, ⌚ = not yet implemented
|
||||||
|
|
||||||
@ -161,3 +162,44 @@ To migrate from RezKonv Suite to Tandoor select `Export > Gesamtes Kochbuch expo
|
|||||||
The generated file can simply be imported into Tandoor.
|
The generated file can simply be imported into Tandoor.
|
||||||
|
|
||||||
As i only had limited sample data feel free to open an issue if your RezKonv export cannot be imported.
|
As i only had limited sample data feel free to open an issue if your RezKonv export cannot be imported.
|
||||||
|
|
||||||
|
## OpenEats
|
||||||
|
OpenEats does not provide any way to export the data using the interface. Luckily it is relatively easy to export it from the command line.
|
||||||
|
You need to run the command `python manage.py dumpdata recipe ingredient` inside of the application api container.
|
||||||
|
If you followed the default installation method you can use the following command `docker-compose -f docker-prod.yml run --rm --entrypoint 'sh' api ./manage.py dumpdata recipe ingredient`.
|
||||||
|
|
||||||
|
Store the outputted json string in a `.json` file and simply import it using the importer. The file should look something like this
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"model":"recipe.recipe",
|
||||||
|
"pk":1,
|
||||||
|
"fields":{
|
||||||
|
"title":"Tasty Chili",
|
||||||
|
...
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...
|
||||||
|
{
|
||||||
|
"model":"ingredient.ingredientgroup",
|
||||||
|
"pk":1,
|
||||||
|
"fields":{
|
||||||
|
"title":"Veges",
|
||||||
|
"recipe":1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...
|
||||||
|
{
|
||||||
|
"model":"ingredient.ingredient",
|
||||||
|
"pk":1,
|
||||||
|
"fields":{
|
||||||
|
"title":"black pepper",
|
||||||
|
"numerator":1.0,
|
||||||
|
"denominator":1.0,
|
||||||
|
"measurement":"dash",
|
||||||
|
"ingredient_group":1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user